C. Fly

链接:http://codeforces.com/group/1EzrFFyOc0/contest/1011/problem/C

题型:binary search 、math。

题意:总共有n个星球,飞船从地球起飞经过n-2个星球(在每个星球上做降落、起飞的动作)到达火星,在火星上同样降落起飞,然后直接返回地球做降落。每个星球起飞所需的燃料质量为ai,降落所需要的燃料质量为bi。飞船本身载重为m,附加燃料质量为所求值。问至少需要多少质量的燃料使得地球能做完整的往返运动,精度为1e-6。

题解:可以用二分也可以不用二分,做这道题之前还不会二分精度,太懒了啥都没学。不用二分就是从回到地球往前推,抓住此时的飞船质量是m。

式子就是 ans=ans*c[i]*1.0/(c[i]-1),c[i]存的是起飞降落的燃料,起飞和降落间隔着存。c[i]<=-1则无解。

二分精度就拿同学的代码看了一下。

/*math*/
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <map>
#include <vector>
#include <cmath>
#include <set>
#define ll long long
#define PI 3.1415926535
#define AC ios::sync_with_stdio(0)
using namespace std;
const int inf=;
/*bool cmp(const vector<pair<int,int> >& a,const vector<pair<int,int> >& b)
{
return a.second<b.second;
}*/
//map<int,int>mp;
//vector<pair<int,int> >vec;
//map<int,int>mp2;
double a[inf];
double b[inf];
double c[];
int main()
{
ios::sync_with_stdio();
ll n,m;
cin>>n;
cin>>m;
for(int i=;i<=n;i++)
{
cin>>a[i];
//a[i]*=1e10;
} for(int i=;i<=n;i++)
{
cin>>b[i];
//b[i]*=1e10;
}
int t=;
for(int i=;i<n;i++)
{
c[++t]=a[i];
c[++t]=b[i+];
}
c[++t]=a[n];
c[++t]=b[];
double ans=m;
for(int i=t;i>=;i--)
{
if(c[i]<=)
{
cout<<-;
return ;
}
ans=ans*c[i]*1.0/(c[i]-);
}
printf("%.8f",ans-m);
}
/*binary search*/
#include<cstdio>
double a[];
double b[];
int main(void)
{
int n;
double m;
scanf("%d%lf\n",&n,&m);
for(int i=;i<n;i++)
scanf("%lf",&a[i]);
for(int i=;i<n;i++)
scanf("%lf",&b[i]);
double l=,r=1e9+;
while(r-l>=0.0000001&&l<=1e9) // Attention
{
double mid=(r+l)/;
double sum=m+mid;
double k=,t=;
int x=,y=;
while()
{
sum-=sum/a[x];
sum-=sum/b[y];
if(x==n-)
{
break;
}
x++;
y++;
if(y==n)
y=;
}
if(sum>m)
r=mid;
else if(sum<m)
l=mid;
else
{
r=mid; // l 或者 r
break;
}
}
if(l>1e9)
printf("-1\n");
else
printf("%f\n",r); // l 或者 r 或者 mid
return ;
}

7-27 Codeforces Round #499 (Div. 2)的更多相关文章

  1. Codeforces Round #499 (Div. 2)

    Codeforces Round #499 (Div. 2) https://codeforces.com/contest/1011 A #include <bits/stdc++.h> ...

  2. Codeforces Round #499 (Div. 1)部分题解(B,C,D)

    Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...

  3. Codeforces Round #499 (Div. 1)

    Codeforces Round #499 (Div. 1) https://codeforces.com/contest/1010 为啥我\(\rm Div.1\)能\(A4\)题还是\(\rm s ...

  4. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  5. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  6. Codeforces Round #499 (Div. 2) C Fly题解

    题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...

  7. Codeforces Round #499 (Div. 2) Problem-A-Stages(水题纠错)

    CF链接  http://codeforces.com/contest/1011/problem/A Natasha is going to fly to Mars. She needs to bui ...

  8. Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)

    C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  9. Codeforces Round #499 (Div. 2)(1011)

    Natasha is planning an expedition to Mars for nn people. One of the important tasks is to provide fo ...

随机推荐

  1. GenericServlet

    Generic-汉语意思:类的adj GenericServlet是一个抽象类,它的源码很容易看懂,继承Servlet接口和ServletConfig接口 所有它里面有父接口里面的方法,所以它就是在S ...

  2. [jquery.validate]自定义方法实现"手机号码或者固定电话"的逻辑验证

    最近项目开发中遇到这样的需求“手机号码或者固话至少填写一个”,如下图所示: 项目采用的jquery.validate.js验证组件,目前组件不支持这种“或”逻辑的验证,于是就自己定义一个 jQuery ...

  3. javascript的ES6学习总结(第二部分)

    1.数组循环 介绍数组循环之前,先回顾一下ES5数组的循环 (1)数组遍历(代替普通的for):arr.forEach(callback(val,index,arr){todo}) //val是数组的 ...

  4. Mac OS 安装robotframework

    1,查看当前系统默认的Python路径 which python1==> /usr/bin/python 2,查看当前python 版本 python1==> Python 2.7.10 ...

  5. 把玩Pencil项目之编译并运行

    Pencil是个好项目.使用Electron作为运行环境,如同Vs Code一样,将JS跨平台桌面应用做了一个好的示范.个人很喜欢这种方式,毕竟多年来关注Web全栈开发,有一种JS一统天下的感觉.我的 ...

  6. java基础语法(三大基础)

    一.标识符 标识符是用于包名.类名.变量名.方法名.对象名.数组名.集合名等的命名:   规则: (1)可以使用英文字母.阿拉伯数字.下划线_.$符号 (2)不能以数字开头 (3)不能使用Java中的 ...

  7. PostgreSQL 9.5.x的架构图及外存图

  8. 【论文速读】ChengLin_Liu_ICCV2017_Deep_Direct_Regression_for_Multi-Oriented_Scene_Text_Detection

    ChengLin Liu_ICCV2017_Deep Direct Regression for Multi-Oriented Scene Text Detection 作者 关键词 文字检测.多方向 ...

  9. 制作Win10 U盘版移动便携系统

    制作U盘Win10 灌装WIM VHD_OneKey_beta2 把wim导入VHD文件 复制 WIN8USB.VHD boot bootmgr三个文件到U盘 把制作的Win10的VHD文件重命名为 ...

  10. 20175205 2018-2019-2 《Java程序设计》第五周学习总结

    20175205 2018-2019-2 <Java程序设计>第五周学习总结 教材学习内容总结 接口:使用关键字interface定义接口 接口声明:interface 接口名 接口体:接 ...