zoukankan      html  css  js  c++  java
  • World Finals 2017

    Need for Speed

    /problems/speed/file/statement/en/img-0001.png
     
    Sheila is a student and she drives a typical student car: it is old, slow, rusty, and falling apart. Recently, the needle on the speedometer fell off. She glued it back on, but she might have placed it at the wrong angle. Thus, when the speedometer reads ss, her true speed is s+cs+c, where cc is an unknown constant (possibly negative).

    Sheila made a careful record of a recent journey and wants to use this to compute cc. The journey consisted of nn segments. In the ithith segment she traveled a distance of didi and the speedometer read sisi for the entire segment. This whole journey took time tt. Help Sheila by computing cc.

    Note that while Sheila’s speedometer might have negative readings, her true speed was greater than zero for each segment of the journey.

    Input

    The first line of input contains two integers nn (1n10001≤n≤1000), the number of sections in Sheila’s journey, and tt(1t1061≤t≤106), the total time. This is followed by nn lines, each describing one segment of Sheila’s journey. The ithith of these lines contains two integers didi (1di10001≤di≤1000) and sisi (|si|1000|si|≤1000), the distance and speedometer reading for the ithith segment of the journey. Time is specified in hours, distance in miles, and speed in miles per hour.

    Output

    Display the constant cc in miles per hour. Your answer should have an absolute or relative error of less than 10610−6.

    Sample Input 1Sample Output 1
    3 5
    4 -1
    4 0
    10 3
    
    3.000000000
    
    Sample Input 2Sample Output 2
    4 10
    5 3
    2 2
    3 6
    3 1
    
    -0.508653377

    wa了好久了,搞不懂二分范围,以为-1000到1e6+1000就够了,我一开大范围反而得不到答案

    通过读题列出通项公式,很容易想到二分操作

    #include<bits/stdc++.h>
    #define eps 1e-8
    using namespace std;
    typedef long long ll;
    double a[1005],b[1005];
    int n,m;
    double solve(){
        double l=-1<<30,r=1<<30,mid;
        for(int i=0;i<n;i++)
        l=max(l,-b[i]);
        for(int i=0;i<10000;i++){
            mid=(l+r)/2;
            double sum=0.0;
            for(int j=0;j<n;j++){
                sum+=a[j]/(mid+b[j]);
            }
            if(sum-m>0) l=mid;
            else r=mid;
        }
        return r;
    }
    int main(){
        cin>>n>>m;
        for(int i=0;i<n;i++)
        cin>>a[i]>>b[i];
        double ans=solve();
        printf("%.8lf
    ",ans);
    }
    View Code
  • 相关阅读:
    IP地址、手机归属和身份证查询接口
    如何用SQL语句给表增加字段? 如何分区视图?
    屏蔽IE的图片工具条,防止图片被轻易保存的一种方法
    转 无依赖Office资源的导入导出
    Asp.Net Winform 条形码系列之Code39 Code39 Of .Net BarCode Serial Blog
    搬家了。。
    POJ 3162 Walking Race(dfs+单调队列)
    HDOJ 4389 X mod f(x) (数位DP)
    POJ 1947 Rebuilding Roads(树DP)
    POJ 1155 TELE(二分+树DP)
  • 原文地址:https://www.cnblogs.com/BobHuang/p/6916799.html
Copyright © 2011-2022 走看看