链接:http://codeforces.com/contest/1011/problem/C
题意:有n个星球,1代表地球(最终都要回到地球),然后输入一个m表示火箭的重量,然后输入了两组n个数,第一组表示在每个星球起飞时消耗一吨燃料的质量数,a[i]就表示每a[i]吨就要消耗1吨燃料,第二组就表示在每个星球降落时消耗一吨燃料的质量数,然后问当火箭从1飞到2到3....到n星球后又返回1星球最少需要加多少燃料。
思路:设最初火箭加燃料共重1吨,然后暴力
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5000+7;
#define ll long long
#define eps 1e-9
inline int read()
{
char ch = getchar(); int x = 0, f = 1;
while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
return x * f;
}
int n, m, a[maxn], b[maxn];
int main()
{
n = read(); m = read();
for(int i = 0; i < n; i++) a[i] = read();
for(int i = 0; i < n; i++) b[i] = read();
b[n] = b[0];
double ans = 1;
for(int i = 0; i < n; i++)
{
ans -= ans/a[i];
ans -= ans/b[i+1];
}
if(ans < eps) puts("-1");
else printf("%.10f\n",m/ans-m);
return 0;
}