7-27 Codeforces Round #499 (Div. 2)
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)的更多相关文章
- Codeforces Round #499 (Div. 2)
Codeforces Round #499 (Div. 2) https://codeforces.com/contest/1011 A #include <bits/stdc++.h> ...
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- Codeforces Round #499 (Div. 1)
Codeforces Round #499 (Div. 1) https://codeforces.com/contest/1010 为啥我\(\rm Div.1\)能\(A4\)题还是\(\rm s ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #499 (Div. 2) D. Rocket题解
题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- SM3杂凑算法Python语言实现——第三部分
SM3杂凑算法实现--第三部分 一.SM3 密码概述 我们首先把需要用到的算法呈现出来,最后我们再考虑如何集合为一个库的方法,这一部分我们就开始编写一个新的算法:国家商用密码标准SM3密 ...
- python之str字符串
字符串是python非常重要的数据类型,它是一个序列(列表和元组也是序列),有下标,可以通过下标遍历字符串序列:同时字符串也是一个不可变数据类型,每次使用"+"拼接字符串时都会产生 ...
- Linux学习----gdb调试(指针的指针)
昨天遇到一个很奇怪的问题,如下: 按照理论,最后*p的值应该是99,不知为什么是15了,所以今天记录用gdb调试的过程,并熟悉gdb的使用. (调试过程参考:http://www.cnblogs.co ...
- VUE-001-在表格单元格(el-table-column)中添加超链接访问
在进行前端网页开发时,通常列表数据我们使用table展示.那么如何在 el-table-column 单元格中使用超链接呢? 如下即是解决方式的一种: 仅需要将如下代码: <el-table-c ...
- Yoink Mac版(临时文件存储助手)中文版
Yoink Mac版是Mac上一款临时文件存储助手,当你拖动文件时Yoink for Mac就会出现,拖放文件到Yoink窗口中即可,需要文件时随时都能从Yoink窗口中拖出文件,使用非常便捷,小编准 ...
- subprocess.CalledProcessError: Command ‘(‘lsb_release’, ‘-a’)’ returned non-zero exit status 1.
解决方法find / -name lsb_releaserm -rf /usr/bin/lsb_release
- charles-抓包Andriod 手机的设置
长按弹出 修改后: charles如果不配置SSL通用证书: 会导致HPPTS协议的域名抓取失败/乱码的现象: 现在SSL越来越多,很多博客都上了SSL,支付相关的行业更是基础配置: charles配 ...
- 前端多选插件bootstrap-select的使用
一.分别引入bootstrap-select.min.js和bootstrap-select.min.css文件 二.在页面中写一个class为selectpicker的select控件 <se ...
- C++模板的要点
1.函数模板与普通函数的区别: 普通函数可以进行自动类型转化,而函数模板不可以. 举个例子 //函数模板 template<class T> void show(T a,T b){ cou ...
- Unity shader之ColorMask
Color Mask解释,见unity文档: ColorMask ColorMask RGB | A | 0 | any combination of R, G, B, A Set color cha ...