WF2017 E
WF最水的题 没有之一 二分答案即可
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<ctime> 5 #include<iostream> 6 #include<algorithm> 7 #include<queue> 8 #include<set> 9 #define inf (0x7fffffff) 10 #define l(a) ((a)<<1) 11 #define r(a) ((a)<<1|1) 12 #define b(a) (1<<(a)) 13 #define esp (1e-8) 14 #define rep(i,a,b) for(int i=a;i<=(b);i++) 15 #define clr(a) memset(a,0,sizeof(a)) 16 typedef long long ll; 17 typedef unsigned long long ull; 18 using namespace std; 19 int readint(){ 20 int t=0,f=1;char c=getchar(); 21 while(!isdigit(c)){ 22 if(c=='-') f=-1; 23 c=getchar(); 24 } 25 while(isdigit(c)){ 26 t=(t<<3)+(t<<1)+c-'0'; 27 c=getchar(); 28 } 29 return t*f; 30 } 31 const int maxn=10009; 32 int n,t,a[maxn],b[maxn]; 33 double L=-1e9,R=1e9; 34 int main(){ 35 //freopen("#input.txt","r",stdin); 36 //freopen("#output.txt","w",stdout); 37 n=readint();t=readint(); 38 rep(i,1,n){ 39 a[i]=readint();b[i]=readint(); 40 L=max(L,double(-b[i]+esp)); 41 } 42 while(abs(L-R)>esp){ 43 double t1=0,mid=(L+R)/2; //cout<<L<<' '<<R<<' '<<mid<<' '; 44 rep(i,1,n) t1+=a[i]*1.0/(b[i]+mid);//cout<<t1<<endl; 45 if(t1>t) L=mid; 46 else R=mid; 47 } 48 printf("%.9lf",L); 49 //fclose(stdin); 50 //fclose(stdout); 51 return 0; 52 }