Each refueling station can determine the upper and lower bounds of an alpha, take the maximum lower bound, take the upper bound, and see if the next gas station satisfies the conditions between the two is unique.
Because you can use fractions, everything is useless double.
#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;ll gcd (ll a,ll b) {returnB?GCD (b,a%b): A; }structfra{ll P,q; Fra (ll x=0, ll y =1):p (x), q (y) {normal (p,q);} voidNormal (ll &p,ll &q) {ll g = gcd (p,q); p/=g; q/=G;} Fraoperator= (intx) {p = x; q =1;return* This; } Fraoperator= (ll x) {p = x; q =1;return* This; } Fraoperator- () {return{-P,q}; } Fraoperator+ (Fra &R) {ll m,n; M= p*r.q+r.p*Q; N= q*r.q; Normal (M,n); return{m,n}; } Fraoperator+ = (fra& r) {return* This= * This+R;} Fraoperator-(Fra &r) {return(-R) + * This; } Fraoperator-= (Fra &r) {return* This= * This-R;} Fraoperator* (Fra &R) {ll m,n; M= p*R.P; N= q*r.q; Normal (M,n); return{m,n}; } Fraoperator*= (Fra &r) {return(* This) = (* This)*R;} Fraoperator/(Fra &r) {returnFra (R.Q,R.P) * (* This); } Fraoperator/= (Fra &r) {return(* This) = (* This)/R;} BOOL operator== (Constfra& R)Const{returnP*R.Q = = r.p*Q;} BOOL operator< (Constfra& R)Const{returnP*R.Q < r.p*Q;} voidPrint () {normal (P,Q);if(q<0) Q =-q,p =-P; printf"%lld/%lld\n", p,q); }};Const intMAXN = 1e3+5;Constll INF =1e16;intMain () {//freopen ("In.txt", "R", stdin); intN scanf"%d",&N); Fra Low (0), High (INF); for(inti =1; I <= N; i++){ intT scanf"%d",&t); Low= Max (Fra (t*Ten, i), low); High= Min (Fra (t*Ten+Ten, I), high); } Low= Fra (n+1)*Low ; High= Fra (n+1)*High ; intU = (high.p-1)/high.q; intD = (LOW.P)/low.q; if(u/Ten! = d/Ten) {puts ("Not unique"); }Else{printf ("unique\n%d", d/Ten); } return 0;}
Codeforces 48C d-the Race