E

解题关键:二分时注意C函数的单调性。

 

 1 #include<bits/stdc++.h>
 2 #define eps 1e-8
 3 #define INF 0x3f3f3f3f
 4 using namespace std;
 5 typedef long long ll;
 6 double a[1000002],b[1000002];
 7 int n,m;
 8 double solve(){
 9     double l=-INF,r=1e9,mid;
10     for(int i=0;i<n;i++) l=max(l,-b[i]);
11     for(int i=0;i<10000;i++){
12         mid=(l+r)/2;
13         double sum=0.0;
14         for(int j=0;j<n;j++){
15             sum+=a[j]/(mid+b[j]);
16         }
17         if(sum-m>0) l=mid;
18         else r=mid; 
19     }
20     return r;
21 }
22 int main(){
23     cin>>n>>m;
24     for(int i=0;i<n;i++) cin>>a[i]>>b[i];
25     double ans=solve();
26     printf("%.8lf\n",ans);
27 } 
E

相关文章:

  • 2022-12-23
  • 2022-02-22
  • 2021-07-06
  • 2021-12-06
  • 2021-05-27
  • 2021-11-13
  • 2022-12-23
猜你喜欢
  • 2021-11-09
  • 2021-12-27
  • 2021-07-20
  • 2022-12-23
  • 2021-07-24
  • 2021-04-14
相关资源
相似解决方案