题面链接:https://codeforces.com/contest/1011/problem/C
类型:模拟
题意:从地球起飞->星球1降落->星球1起飞->星球2起飞->······->星球n-1起飞->地球降落
题解:逆过程模拟,如果费用存在<=1的就直接输出-1
import java.util.Scanner;
public class C {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int n=kb.nextInt();
double sum=kb.nextDouble();
double sum1=0;
double aa;
double a[]=new double[n];
double b[]=new double[n];
boolean pd=false;
for(int i=0;i<n;i++) {
a[i]=kb.nextDouble();
if(a[i]<1.1)pd=true;
}
for(int i=0;i<n;i++) {
b[i]=kb.nextDouble();
if(b[i]<1.1)pd=true;
}
if(pd) {
System.out.println(-1);
return;
}
aa=sum/(b[0]-1);
sum1+=aa;
sum+=aa;
for(int i=n-1;i>0;i--) {
aa=sum/(a[i]-1);
sum1+=aa;
sum+=aa;
aa=sum/(b[i]-1);
sum1+=aa;
sum+=aa;
}
aa=sum/(a[0]-1);
sum1+=aa;
sum+=aa;
System.out.println(sum1);
kb.close();
}
}