题目描述

已知$\sum\limits_{i=1}^n\frac{d_i}{s_i+c}=t$,求$c$ $(d_i>0,s_i+c>0)$

输入

第一行包含两个整数n(1≤n≤1000)和t(1≤t≤10^6),分别表示Sheila的行程段数和总时间。
接下来n行,每行描述了Sheila的一段行程。
第i行包含两个整数di(1≤di≤1000)和si(|si|≤1000),分别表示第 i 段行程的距离和表盘读数。
时间单位是小时,距离单位是英里,速度单位是英里每小时。

输出

输出常数c,其单位是英里每小时。你的答案绝对或相对误差应该小于10^-6。

样例输入

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 二分的更多相关文章

  1. 【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. ...

  2. 【BZOJ4952】lydsy七月月赛 E 二分答案

    [BZOJ4952]lydsy七月月赛 E 题面 题解:傻题...二分答案即可,精度有坑. #include <cstdio> #include <cstring> #incl ...

  3. CF2.C(二分贪心)

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. 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 ...

  5. UVa 714 Copying Books(二分)

    题目链接: 传送门 Copying Books Time Limit: 3000MS     Memory Limit: 32768 KB Description Before the inventi ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 精心收集的48个JavaScript代码片段,仅需30秒就可理解

    源文链接 :https://github.com/Chalarangelo/30-seconds-of-code#anagrams-of-string-with-duplicates 该项目来自于 G ...

  2. Fiddler(一)

    Fiddler:学习scrapy,不只是满足于网页上爬去信息的成功乐趣,现在开始接触爬去手机信息了,不好解决,知道过程不会轻松,但自己想去尝试.QAQ 写这篇博客是基于以下的几位大神学习笔记,我只是做 ...

  3. ASPX页面请求响应过程

  4. Hive学习路线图

  5. [CodeForces950C]Zebras

    Description 题目地址: Codeforces 题意:给你一串只含01的字符串,判断能否将字符串分为k个子序列,使得子序列满足以下条件: 开头和结尾都是0 相邻的2个数是01或者10 如0, ...

  6. Leetcode 606. 根据二叉树创建字符串

    题目链接 https://leetcode.com/problems/construct-string-from-binary-tree/description/ 题目描述 你需要采用前序遍历的方式, ...

  7. 笔记-python-module导入技巧

    笔记-python-module导入技巧 1.      module导入技巧 1.1.    控制模块导入内容 在模块中定义 __all__ = [] 不多言,主要是影响from <> ...

  8. HTML5 canvas 圆盘抽奖

    使用html5 canvas 绘制的圆盘抽奖程序 效果图: 贴上全部代码:  1 <!DOCTYPE html> <html> <head> <meta ch ...

  9. WPF仿QQ聊天框表情文字混排实现

    原文:WPF仿QQ聊天框表情文字混排实现 二话不说.先上图 图中分别有文件.文本+表情.纯文本的展示,对于同一个list不同的展示形式,很明显,应该用多个DataTemplate,那么也就需要Data ...

  10. android systemtrace 报错

    折腾了很久,妈的,终于可以跑出来systemtrace了.如果你跟我一样,老是生成trace失败,那么,按我说的啦: 坑就在,你必须选一个路径存放trace.html,你不选一个,他就生成不了. 打开 ...