Codeforces 1011C Fly(二分+模拟)
题意:
是有n个星球,1代表地球,然后输入一个m表示火箭的重量,然后输入了两组n个数,第一组表示在每个星球起飞时消耗一吨燃料的质量数,a[i]就表示每a[i]吨就要消耗1吨燃料,第二组就表示在每个星球降落时消耗一吨燃料的质量数,然后问当火箭从1飞到2到3....到n星球后又返回1星球最少需要加多少燃料。
思路:
二分答案,注意double二分的写法,以及如何控制出口
代码:
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<list> #define fst first
#define sc second
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))
#pragma Gcc optimize(2) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const int maxn = + ;
const int maxm = 5e3 + ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
int scan(){
int res=,ch,flag=;
if((ch=getchar())=='-')
flag=;
else if(ch>=''&&ch<='')
res=ch-'';
while((ch=getchar())>=''&&ch<='')
res=res*+ch-'';
return flag?-res:res;
} double a[maxn], b[maxn];
int n, m;
bool ok(double ans){
for(int i = ; i <= n; i++){
ans -= (m+ans)/a[i];
ans -= (m+ans)/b[i+];
}
if(ans < ) return false;
else return true;
}
int main(){
scanf("%d",&n);
scanf("%d", &m); for(int i = ; i <= n; i++){
scanf("%lf", &a[i]);
if(a[i] <= ){
printf("-1");
return ;
}
}
for(int i = ; i <= n; i++){
scanf("%lf", &b[i]);
if(b[i] <= ){
printf("-1");
return ;
}
}b[n+] = b[];
double ans = ;
double l = , r = ;
for(int i = ; i <= ; i++){
if(r-l < 1e-) break;
double mid = (l+r)/2.0;
if(ok(mid))r = mid;
else l = mid;
}
printf("%.10lf", l);
return ;
}
/*
*/
Codeforces 1011C Fly(二分+模拟)的更多相关文章
- codeforces#1011C. Fly (二分,注意精度)
题意:火箭经过1到n号星球,并回到1号星球,现在给出每消耗一砘燃油能带起的火箭质量a[i]和b[i],a[i]代表在第i个星球起飞,b[i]代表在第i个星球降落.求出最少消耗的汽油.保证:如果不能完成 ...
- Codeforces 1132D(二分模拟)
要点 二分显然,关键在于怎么判断 题解方法:开k个队列代表每个时间有哪些电脑会挂掉,这部分O(n)预处理一下,之后扫一遍时间,每个时间点贪心选取最靠前的会挂的电脑未雨绸缪给它充电,然后看看充电以后要不 ...
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟
A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- codeforces 732D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复 ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- CodeForces 359D (数论+二分+ST算法)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...
- CodeForces 163B Lemmings 二分
Lemmings 题目连接: http://codeforces.com/contest/163/problem/B Descriptionww.co As you know, lemmings li ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
随机推荐
- Windows和Linux下与VMware虚拟机通过内网IP通讯
首先分两种情况:一种是你的电脑已经在一个内网的环境下且有额外的内网IP地址,和另一种只是想给自己电脑上的虚拟机分配个内网IP来通讯. ①有可用的内网IP 找到一个空闲的IP地址(这里以192.168. ...
- 2019牛客暑期多校第五场题解ABGH
A.digits 2 传送门 题意:给你一个n,要求输出一个每一位数字之和能整除n且其本身也能整除n的数.n不超过100,要求的数不超过10000位数. 题解:直接将n输出n次. 代码: #inclu ...
- FlashFXP 5.0.0官方中文破解版,附文件下载地址和破解码
FlashFXP 5.0.0官方中文破解版是一个功能强大的 FXP/FTP 软件,融合了一些其他优秀 FTP 软件的优点,如像 CuteFTP 一样可以比较文件夹,支持彩色文字显示:像 BpFTP 支 ...
- 对Java中可变参数的理解
说明 可变参数:是DK1.5之后出现的新特性,其实可变参数是0.1.2.3.....个参数的数组 使用前提 当方法的参数列表数据类型已经确定,但是参数的个数不确定,就可以使用可变参数 使用格式 修饰符 ...
- GB国标编码的程序出现乱码
- Spring Boot2 系列教程 (七) | 使用 Spring Data JPA 访问 Mysql
前言 如题,今天介绍 Spring Data JPA 的使用. 什么是 Spring Data JPA 在介绍 Spring Data JPA 之前,首先介绍 Hibernate . Hibernat ...
- 最短路SPFA模板
// // dijkstra妯℃澘.cpp // algorithm // // Created by david.xu on 2018/8/6. // Copyright 漏 2018骞?david ...
- Fibnoccia 数列简单题
In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, ...
- Django 滑动验证
极验官网:https://www.geetest.com/ 文档: https://docs.geetest.com/ 查看 行为验证的部署文档
- ORM基础4 跨表查询+原子性操作
一.跨表查询 1.# # 正向查找 对象查找 # book_obj = models.Book.objects.get(id=3) # print(book_obj) # ret = book_obj ...