【bzoj4952】[Wf2017]Need for Speed 二分
题目描述
输入
输出
样例输入
3 5
4 -1
4 0
10 3
样例输出
3.000000000
题解
二分
由于给出的函数是单调的,因此可以直接二分c的取值并判断即可。
注意精度问题,最好使用long double并进行固定100次二分迭代。
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long double ld;
ld d[1010] , s[1010];
int main()
{
int n , i , cnt = 100;
ld t , l = 1e18 , r = 1e18 , mid , ret;
scanf("%d%Lf" , &n , &t);
for(i = 1 ; i <= n ; i ++ ) scanf("%Lf%Lf" , &d[i] , &s[i]) , l = min(l , s[i]);
l = -l;
while(cnt -- )
{
mid = (l + r) / 2 , ret = 0;
for(i = 1 ; i <= n ; i ++ ) ret += d[i] / (s[i] + mid);
if(ret < t) r = mid;
else l = mid;
}
printf("%.9Lf\n" , l);
return 0;
}
【bzoj4952】[Wf2017]Need for Speed 二分的更多相关文章
- 【2017 World Final E】Need For Speed(二分)
Sheila is a student and she drives a typical student car: it is old, slow, rusty, and falling apart. ...
- 【BZOJ4952】lydsy七月月赛 E 二分答案
[BZOJ4952]lydsy七月月赛 E 题面 题解:傻题...二分答案即可,精度有坑. #include <cstdio> #include <cstring> #incl ...
- CF2.C(二分贪心)
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 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 ...
- UVa 714 Copying Books(二分)
题目链接: 传送门 Copying Books Time Limit: 3000MS Memory Limit: 32768 KB Description Before the inventi ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 二分
C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #367 (Div. 2) A B C 暴力 二分 dp(字符串的反转)
A. Beru-taxi time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
随机推荐
- java基础 序列化反序列化流 实现Serializable 接口 自动装载序列号到对象文本文件如修改不能反序列化对象文本,除非自定义long型常量 打印流
package com.swift.baseKnowledge; import java.io.File; import java.io.FileInputStream; import java.io ...
- 用IDEA搭建基于maven的springboot项目
第一步:新建一个Project 第二步:选择Spring Initializr和SDK 然后next 第三步:修改Group和Artifact 第四步:按自己的需求选,这里我选的是Web,然后ne ...
- Dijkstra&&Floyd
文章来源:(http://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html) (以下内容皆为转载) Dijkstra算法 1.定义 ...
- Linux下文件的压缩与解压缩
一.zip格式 zip可能是目前使用的最多的文档压缩格式.它最大的优点就是在不同的操作系统平台上使用.缺点就是支持 的压缩率不是很高,而tar.gz和tar.bz2在压缩率方面做得非常好. 我们可以使 ...
- SAP BI 常用TCODE
S.No Tcode Description 1 RSA1 Administrator Work Bench 2 RSA11 Calling up AWB with the IC tree 3 RSA ...
- PHP siege 压测 QPS大小
1.使用 PHP-FPM SOCKET的形式通讯 2.配置 PHP-FPM配置 [root@bogon php-fpm.d]# ls -al 总用量 drwxr-xr-x. root root 8月 ...
- POJ 2676 数独(DFS)
Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21612 Accepted: 10274 Specia ...
- 17-比赛2 F - Fox And Two Dots (dfs)
Fox And Two Dots CodeForces - 510B ================================================================= ...
- 原理剖析-Netty之服务端启动工作原理分析(上)
一.大致介绍 1.Netty这个词,对于熟悉并发的童鞋一点都不陌生,它是一个异步事件驱动型的网络通信框架: 2.使用Netty不需要我们关注过多NIO的API操作,简简单单的使用即可,非常方便,开发门 ...
- 容器技术Docker
什么是decker容器 简单理解就是将代码和部署环境一起打包的一个容器