题目描述

已知$\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. 14、SpringBoot------定制错误返回内容json格式

    开发工具:STS 前言: 在前后端分离的项目中,当前端向后端请求资源失败时,想知道具体的错误原因,给用户予以提示. 但是,在springboot中返回内容是固定的.并不适合我们前端进行分析. 所以,就 ...

  2. 第8条:覆盖equals时请遵守通用约定

    第8条:覆盖equals时请遵守通用约定 引言:尽管Object是一个具体类,但是设计它主要是为了拓展.它所有的非final方法(equals.hashCode.toString.clone和fina ...

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

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

  4. 03-UI控件浏览

    UI控件浏览 可能用得上的UI控件 为了便于开发者打造各式各样的优秀app,UIKit框架提供了非常多功能强大又易用的UI控件 下面列举一些在开发中可能用得上的UI控件(红色表明最常用,蓝色代表一般, ...

  5. Java分享笔记:使用entrySet方法获取Map集合中的元素

    /*--------------------------------- 使用entrySet方法取出Map集合中的元素: ....该方法是将Map集合中key与value的关系存入到了Set集合中,这 ...

  6. CentOS使用yum安装drbd

    CentOS 6.x系统要升级到最新的内核才支持 CentOS 6.x rpm -ivh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noa ...

  7. Jenkins持续化集成

    Jenkins介绍 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 1.持续的软件版本发布/测试项目. 2.监控外部调用执行的工作. 安装环境 操作系统:lin ...

  8. 用python写一个类似于linux中的tree

    import os filePath = 'g:/File' j = 0 # 查找的深度计数 def tree(filePath,j): dir_now = os.listdir(filePath) ...

  9. 详解JavaScript中的arc的方法

    今天说说JavaScript在网页中画圆的函数arc! 一.arc所需要的参数设置 1 arc(x, y, radius, startAngle, endAngle, counterclockwise ...

  10. Open source cryptocurrency exchange

    Peatio: https://github.com/peatio/peatio ViaBTC: https://github.com/viabtc/viabtc_exchange_server