/*greedy: According to the order of the left and the left hand product from small to large: the pre-i-1 term calculated for S i:a bi+1:c D so i+1 gold coins for s*a/d I at s/b exchange I and i+1 i:c di+1:a b so i+1 gold coins for s*c/b I place for s/d Now let's assume that the exchange I and i+1 will get a better solution (the first item before and after the exchange is obviously less than the i+1 item so the comparison is i+1) there is s*a/d > s*c/b-A/d > c/b--a*b>c*d so by product from small To a certain optimal and then the high-precision 0.0*/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#definell Long Longusing namespacestd;ll n,c[10001],cc[10001],b[10001],d[10001],ans[10001];structnode{intl; intR;} a[1001];intcmpConstNode &x,ConstNode &y) { if(X.L*X.R<Y.L*Y.R)return 1; if(X.L*X.R>Y.L*Y.R)return 0; if(x.l*x.r==y.l*Y.R) {if(X.R>Y.R)return 1; Else return 0; }}BOOLCan ()//do you need to update the final answer{ if(d[0]>ans[0])return 1; if(d[0]<ans[0])return 0; inti; for(i=1; i<=d[0];i++) if(D[i]>ans[i])return 1; if(D[i]<ans[i])return 0; return 0;}voidChengintx) {ll i,j,y=0; for(i=1; i<=c[0];i++) Cc[i]=c[c[0]-i+1]; for(i=1; i<=c[0];i++) {Cc[i]=cc[i]*x+y; Y=cc[i]/Ten; Cc[i]=cc[i]%Ten; } while(y>0)//stripping take care of the last one when taking a single fine{cc[++c[0]]=y%Ten; Y=y/Ten; } for(i=1; i<=c[0];i++) C[i]=cc[c[0]+1-i];}voidChuintx) {memset (b,0,sizeof(b)); memset (d,0,sizeof(d)); inti,p=0, k=1; for(i=1; i<=c[0];i++) {B[i]= (p*Ten+c[i])/x; P= (c[i]+p*Ten)%x; } b[0]=c[0]; for(i=1; i<=b[0];i++) if(b[i]!=0) {k=i; Break; } for(i=k;i<=b[0];i++) D[i-k+1]=B[i]; d[0]=b[0]-k+1; if(Can () &&d[1]!=0) {memset (ans,0,sizeof(ans)); for(i=0; i<=d[0];i++) Ans[i]=D[i]; }}intMain () {CIN>>N; ll I,j,o; N++; for(i=1; i<=n;i++) Cin>>a[i].l>>A[I].R; Sort (a+2, A +1+N,CMP);//Sortc[0]=1; c[1]=1; for(i=2; i<=n;i++) {Cheng (a[i-1].L);//Maintenance C denotes the product of the left hand of the front ownerChu (A[I].R);//then ÷ the person's right hand is credited as Ans } for(j=1; j<=ans[0];j++) cout<<Ans[j]; return 0;}
codevs1198 King Game (greedy)