We sort in ascending order by the product of the right or left hand number to minimize the maximum number of coins.
Why is it?
We know:
1) If the next two people exchange positions, will only affect the value of these two people, will not affect others
2) Assume the adjacent two persons I, i + 1. Set A[i] b[i] <= a[i + 1] b[i + 1],i before everyone's left hand product is S.
ans1 = Max{s/b[i], S * A[i]/b[i + 1]}
Ans2 = max{s/b[i + 1], S * a[i + 1]/b[i]}
Because, A[i] b[i] <= a[i + 1] b[i + 1]
So, S a[i]/b[i + 1] <= s a[i + 1]/b[i]
And because, S/b[i + 1] <= S * A[i]/b[i + 1]
So, ans2 = S * a[i + 1]/b[i]
ans1 = Max{s/b[i], S * A[i]/b[i + 1] (<=s a[i + 1]/b[i])}
So, ans1 <= ans2
As for high precision,
Here is the 60-point code, and yy a bit on the good
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #definell Long Long5 using namespacestd;6 Const intn=20010;7 ll S[n],tmp[n];8 structfx{9 ll L,r,x;Ten}d[1010]; One BOOLCMP (FX a,fx b) { A returna.x<b.x; - } - intMain () { the intN; -ll ans=0, P,q; -scanf"%d",&n); - for(intI=0; i<=n;i++){ +scanf"%lld%lld",&d[i].l,&D[I].R); -d[i].x=d[i].l*D[I].R; + } ASort (d+1, d+n+1, CMP); atp=1; - for(intI=1; i<=n;i++){ -p*=d[i-1].L; - if(ans<p/D[I].R) -ans=p/D[I].R; - } inprintf"%lld", ans); - return 0; to}
-
"The Valley P1080" King game