日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #499 (Div. 2) 1011 C. Fly 二分

發布時間:2024/1/8 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #499 (Div. 2) 1011 C. Fly 二分 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

C. Fly

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on?n?2n?2?intermediate planets. Formally: we number all the planets from?11?to?nn.?11?is Earth,?nn?is Mars. Natasha will make exactly?nn?flights:?1→2→…n→11→2→…n→1.

Flight from?xx?to?yy?consists of two phases: take-off from planet?xx?and landing to planet?yy. This way, the overall itinerary of the trip will be: the?11-st planet?→→?take-off from the?11-st planet?→→?landing to the?22-nd planet?→→?22-nd planet?→→?take-off from the?22-nd planet?→→?……?→→?landing to the?nn-th planet?→→?the?nn-th planet?→→?take-off from the?nn-th planet?→→?landing to the?11-st planet?→→?the?11-st planet.

The mass of the rocket together with all the useful cargo (but without fuel) is?mm?tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that?11?ton of fuel can lift off?aiaitons of rocket from the?ii-th planet or to land?bibi?tons of rocket onto the?ii-th planet.

For example, if the weight of rocket is?99?tons, weight of fuel is?33?tons and take-off coefficient is?88?(ai=8ai=8), then?1.51.5?tons of fuel will be burnt (since?1.5?8=9+31.5?8=9+3). The new weight of fuel after take-off will be?1.51.5?tons.

Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.

Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.

Input

The first line contains a single integer?nn?(2≤n≤10002≤n≤1000)?— number of planets.

The second line contains the only integer?mm?(1≤m≤10001≤m≤1000)?— weight of the payload.

The third line contains?nn?integers?a1,a2,…,ana1,a2,…,an?(1≤ai≤10001≤ai≤1000), where?aiai?is the number of tons, which can be lifted off by one ton of fuel.

The fourth line contains?nn?integers?b1,b2,…,bnb1,b2,…,bn?(1≤bi≤10001≤bi≤1000), where?bibi?is the number of tons, which can be landed by one ton of fuel.

It is guaranteed, that if Natasha can make a flight, then it takes no more than?109109?tons of fuel.

Output

If Natasha can fly to Mars through?(n?2)(n?2)?planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number??1?1.

It is guaranteed, that if Natasha can make a flight, then it takes no more than?109109?tons of fuel.

The answer will be considered correct if its absolute or relative error doesn't exceed?10?610?6. Formally, let your answer be?pp, and the jury's answer be?qq. Your answer is considered correct if?|p?q|max(1,|q|)≤10?6|p?q|max(1,|q|)≤10?6.

Examples

input

Copy

2 12 11 8 7 5

output

Copy

10.0000000000

input

Copy

3 1 1 4 1 2 5 3

output

Copy

-1

input

Copy

6 2 4 6 3 3 5 6 2 6 3 6 5 3

output

Copy

85.4800000000

Note

Let's consider the first example.

Initially, the mass of a rocket with fuel is?2222?tons.

  • At take-off from Earth one ton of fuel can lift off?1111?tons of cargo, so to lift off?2222?tons you need to burn?22?tons of fuel. Remaining weight of the rocket with fuel is?2020?tons.
  • During landing on Mars, one ton of fuel can land?55?tons of cargo, so for landing?2020?tons you will need to burn?44?tons of fuel. There will be?1616?tons of the rocket with fuel remaining.
  • While taking off from Mars, one ton of fuel can raise?88?tons of cargo, so to lift off?1616?tons you will need to burn?22?tons of fuel. There will be?1414?tons of rocket with fuel after that.
  • During landing on Earth, one ton of fuel can land?77?tons of cargo, so for landing?1414?tons you will need to burn?22?tons of fuel. Remaining weight is?1212?tons, that is, a rocket without any fuel.

In the second case, the rocket will not be able even to take off from Earth.

?

思路:二分燃料重量

#include <cstdio> #include <algorithm> #include <math.h> #include <string.h> #include <vector> #include <iostream> #define ll long long #define INF 0x3f3f3f using namespace std; const int N=1000+1000; double a[N],b[N]; double m; int n; int ok(double x) {double fuel,w,cost;int i;fuel=x;w=m+fuel;cost=w/(a[1]*1.0);fuel-=cost;if(fuel<=0) return 0;for(i=2;i<=n;i++){w=m+fuel;cost=w/(b[i]*1.0);fuel-=cost;if(fuel<=0) return 0;w=m+fuel;cost=w/(a[i]*1.0);fuel-=cost;if(fuel<=0) return 0;}w=m+fuel;cost=w/(b[1]*1.0);fuel-=cost;if(fuel<0) return 0;return 1; } int main() {int i;int flag=0;double l,r,mid;scanf("%d",&n);scanf("%lf",&m);for(i=1;i<=n;i++) scanf("%lf",&a[i]);for(i=1;i<=n;i++) scanf("%lf",&b[i]);l=1.0;r=10000000000.0;while(r-l>=0.000001){mid=(l+r)/2.0;if(ok(mid)){r=mid;flag=1;}else l=mid;}if(flag==0) printf("-1\n");else printf("%lf\n",mid);return 0; }

?

總結

以上是生活随笔為你收集整理的Codeforces Round #499 (Div. 2) 1011 C. Fly 二分的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。