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. Kali 开启 SSH 服务方法

    尝试了开启kali的ssh,方法如下: 1.修改sshd_config文件.命令:vim /etc/ssh/sshd_config 2.将#PasswordAuthentication no的注释去掉 ...

  2. shell 字符串比较 算数比较 文件条件测试

    set-group-id即set-gid -->授予了程序其所在组的访问权限 set-user-id即set-uid -->授予了程序其拥有者的访问权限而不是其使用者的访问权限 set-g ...

  3. VUE-009-页面打开时初始化配置项内容

    网页开发过程中,尤其是在表单开发过程中,不可避免的会有各种各样的基础数据需要展示,供用户使用.例如,大家在办理信用卡时,经常需要填写各种表单数据,其中:性别(男.女).学历(高中及以下.大专.本科.研 ...

  4. Spark入门到精通--(第九节)环境搭建(Hive搭建)

    上一节搭建完了Hadoop集群,这一节我们来搭建Hive集群,主要是后面的Spark SQL要用到Hive的环境. Hive下载安装 下载Hive 0.13的软件包,可以在百度网盘进行下载.链接: h ...

  5. jsp的环境搭建

    JSP : 动态网页 一.静态和动态的区别: 1.是否会随着时间.地点.用户操作的改变而改变. 2.动态网页需要使用服务器端的脚本语言(JSP) 二.BS CS 1.CS:QQ.微信.CS游戏. 缺点 ...

  6. 2019王小的Java学习之路

    文章背景身边有个非常要好的朋友王某某,因为是发小的关系,之后文章统称为王小. 大专毕业后 顺利 的被安排进了某某工厂工作,工作一段时间后,尽管工作比较轻松,却无法忍受终日的流水线生活,经过我的介绍,决 ...

  7. redis集群及相关的使用

    从redis 3.0之后版本支持redis-cluster集群,Redis-Cluster采用无中心结构,每个节点保存数据和整个集群状态,每个节点都和其他所有节点连接. 1.所有的redis节点彼此互 ...

  8. go 语言图片像素点处理

    将一张图片色彩反转,就是将  rgb 值,分别被 255 减 package main import ( "bytes" "fmt" "image&q ...

  9. MySQL SQL Explain输出学习

    MySQL的explain命令语句提供了如何执行SQL语句的信息,解析SQL语句的执行计划并展示,explain支持select.delete.insert.replace和update等语句,也支持 ...

  10. Mysql事务隔离级别学习

    这篇文章主要谈谈Mysql事务隔离级别的区别,以及自己的一些感受. 自己一直以来没搞懂“可重复读”和可提交读“两者之间的区别,通过此次的实践,清楚了两者之间的区别.废话不说,先上图看看这几个事务隔离级 ...