zoukankan      html  css  js  c++  java
  • CodeForces 772A Voltage Keepsake

    二分答案,验证。

    二分到一个答案,比他小的时间都需要补充到这个时间,计算所需的量,然后和能提供的量进行比较。

    #include <cstdio>
    #include <cmath>
    #include <set>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <string>
    #include <vector>
    using namespace std;
    
    int n, p;
    int a[100010],b[100010];
    
    bool check(double x)
    {
        double sum = 0;
        double t = 0;
        for(int i=1;i<=n;i++)
        {
            if(1.0*b[i]/a[i]>=x) continue;
            sum = sum + (x-1.0*b[i]/a[i])*a[i];
        }
    
        if(sum==0) return 1;
        
        if(sum<=x*p) return 1;
        return 0;
    }
    
    int main()
    {
        scanf("%d%d",&n,&p);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i],&b[i]);
        }
    
        double L = 0,R = 100000.0;
        R=R*R;
    
        double INF=R;
    
        double ans;
        int t=100;
        while(t--)
        {
            double mid = (L+R)/2;
    
            if(check(mid)) L=mid,ans=mid;
            else R=mid;
        }
    
        double eps = 1e-7;
        if(abs(ans-INF)<eps) printf("-1
    ");
        else printf("%f
    ",ans);
    
        return 0;
    }
  • 相关阅读:
    Spring----Day03
    Spring----Day02
    python
    python
    python
    python
    python
    python
    python
    python
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6823619.html
Copyright © 2011-2022 走看看