• cf 1011C. Fly


    二分,每次判断经过所有星球是否把油耗光

    #include<bits/stdc++.h>
    using namespace std;
    int a[1010];
    int b[1010];
    int n,m;
    bool check(double x)
    {
        double weight=x+m;
        double tot=x;
        for(int i=1;i<=n;i++)
        {
            if(i==1)
            {
                double tmp=weight/a[i];
                weight-=tmp;
                tot-=tmp;
                if(tot<0)
                  return false;
            }
            else if(i==n)
            {
                double tmp1=weight/b[i];
                weight=weight-tmp1;
                tot-=tmp1;
                if(tot<0)
                  return false;
                double tmp2=weight/a[i];
                weight=weight-tmp2;
                tot-=tmp2;
                if(tot<0)
                  return false;
                double tmp3=weight/b[1];
                weight=weight-tmp3;
                tot-=tmp3;
                if(tot<0)
                  return false;
            }
            else
            {
                double tmp1=weight/b[i];
                weight=weight-tmp1;
                tot-=tmp1;
                if(tot<0)
                  return false;
                double tmp2=weight/a[i];
                weight=weight-tmp2;
                tot-=tmp2;
                if(tot<0)
                  return false;
            }
        }
        return true;
    }
    int main()
    {
        scanf("%d",&n);
        scanf("%d",&m);
        for(int i=1;i<=n;i++)
           scanf("%d",&a[i]);
        for(int i=1;i<=n;i++)
           scanf("%d",&b[i]);
        double le=0,ri=1e9;
        double ans=-1;
        for(int i=1;i<=100;i++)
        {
            double mid=(le+ri)/2;
            if(check(mid))
            {
                ri=mid;
                ans=mid;
            }
            else
            {
                le=mid;
            }
        }
        if(ans>0)
        printf("%.10lf
    ",ans);
        else
        printf("-1
    ");
    }
  • 相关阅读:
    Spark提交任务到集群
    在Spark中使用Kryo序列化
    Linux用户与用户组的详解
    Linux一键安装PHP/JAVA环境OneinStack
    Redis常用命令
    MySQL高效分页解决方案集
    linux 发邮件
    Linux 安全
    Linux Shell 文本处理工具集锦
    MySQL 获得当前日期时间(以及时间的转换)
  • 原文地址:https://www.cnblogs.com/lishengkangshidatiancai/p/10288679.html
Copyright © 2020-2023  润新知