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. 关于parseInt()里的一些小坑

    parseInt(string,radix)方法是将输入字符串转化为数值,两个输入参数中string为要转化的字符串,radix可省略,是浏览器以几进制来解读输入的string. 举几个例子就能够对该 ...

  2. 另存了一次网页之后其它word打开格式都变了

    解决方案: 视图->页面视图 感觉自己很傻...原来另存word为网页后,默认的打开模式就是网页视图了.只需要把视图改回去即可

  3. spring-data-redis2.0以上配置redis连接

    1.所需的maven依赖 <dependency> <groupId>org.springframework.data</groupId> <artifact ...

  4. 4.hadoop的安装与配置

    1.下载hadoop-2.6.2.tar.gz. 2.复制hadoop-2.6.2.tar.gz到/usr/local/目录下. 3解压 #tar  -zxvf  hadoop-2.6.2.tar.g ...

  5. 模拟网络状况工具——clumsy

    官网:http://jagt.github.io/clumsy/index.html 官网上的介绍已经很易懂了,所以本文只是直接翻译了官网内容. clumsy 能在 Windows 平台下人工造成不稳 ...

  6. 创建存储过程 in,out,inout

    in: 输入参数,存储过程如果修改了参数值,那么不能被返回. out:输出参数,存储过程中修改了参数值,可以被返回.inout:输入参数,存储过程如果修改了参数值,可以被返回 注意参数格式:  in  ...

  7. Kali Hydra SSL issue, xHydra (GUI version of Hydra) works just fine

    First find the source code. (https://is.gd/LlS5Sy) - Example search Once located you must download i ...

  8. selenium--控制浏览器和简单元素操作

    控制浏览器1.driver.maximize_window() #浏览器最大化2.driver.set_windows_size(480*800) #浏览器设置成移动端大小(480*800),参数数字 ...

  9. Visual Studio 独立 Shell 下载

    https://visualstudio.microsoft.com/zh-hans/vs/older-downloads/isolated-shell/ SSMS 2017 安装问题 https:/ ...

  10. ansible批量管理

    编写批量安装脚本 [root@m01 scripts]# vim install.sh for ip in $* do echo "=======start install to $ip = ...