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. /etc/init.d/sshd配置SSHD路径忘记修改导致启动失败

    [root@lnlte2dmr3 ~]# bash[root@lnlte2dmr3 ~]# install -v -m700 -d /var/empty/sshdinstall: 正在创建目录&quo ...

  2. 关于VMware(虚拟机) 出现错误时处理办法

    我们在开发中难免会用到虚拟机.前段时间老有同学问我虚拟机报错解决办法,趁今天有空特随笔. 错误如下图 首先科普下VT是个啥? Intel VirtualTechnology(VT)既“虚拟化技术” V ...

  3. vue中用ajax上传文件

    直接上代码 <input class="file-btn" type="file" @change="uploadCompany($event) ...

  4. Python3学习之路~9.2 操作系统发展史介绍、进程与线程区别、线程语法、join、守护线程

    一 操作系统发展史介绍 参考链接:http://www.cnblogs.com/alex3714/articles/5230609.html 二 进程与线程 进程: 对各种资源管理的集合 就可以称为进 ...

  5. 干了这杯Java之transient关键字

    看源码的时候,发现transient这个关键字,不甚理解,查找资料发现:不被序列化 疑问: 静态变量是不是不被序列化? public class User implements Serializabl ...

  6. mat-form-field must contain a MatFormFieldControl错误的解决方法

    下面的代码竟然出错了: <mat-form-field> <input matInput placeholder="输入名称"> </mat-form ...

  7. eslint的安装与使用

    什么是 ESLint ESLint(中文站点)是一个开源的 JavaScript 代码检查工具,使用 Node.js 编写,由 Nicholas C. Zakas 于 2013 年 6 月创建.ESL ...

  8. 在C#中GUID生成的四种格式

    var uuid = Guid.NewGuid().ToString(); // 9af7f46a-ea52-4aa3-b8c3-9fd484c2af12 var uuidN = Guid.NewGu ...

  9. NetCore持续踩坑

    坑1: vs2017 安装 .netcore2.2.2后,新建项目编译报错:.NET SDK 不支持降.NET Core2.2 设置为目标. 我以为是.netcore的sdk版本有误,于是我查看.ne ...

  10. bochs模拟器创建映像文件 、写入文件并启动

    安装 bochs,dd for windows,nasm,并将安装目录加入到环境变量中. 我用的bochs版本是2.6.8 1.用 bochs 中 bximage.exe 创建新的 img 文件 2. ...