Each item has three parameters, actually equivalent to two, because the sum is determined.
Then the problem becomes a pile of points on the two-dimensional plane, and the convex hull of the smallest subset of B is formed, including these points a.
Use a Floyd around a circle.
1 /**************************************************************2 problem:10273 User:rausen4 language:c++5 result:accepted6 time:1136 Ms7 memory:1820 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <cmath> A#include <algorithm> - - #defineP Point the using namespacestd; -typedefDoubleLF; - Const intN =505; - Const intINF =1e9; + ConstLF EPS = 1e-8; - + structPoint { A lf x, y; at P () {} - P (LF _x, LF _y): X (_x), Y (_y) {} - -InlineBOOL operator!= (ConstP p)Const { - returnFabs (x-p.x) > EPS | | Fabs (Y-P.Y) >EPS; - } inInline Poperator-(P p) { - returnP (x-p.x, Y-p.y); to } +Inline LFoperator*(P p) { - returnX * p.y-y *p.x; the } * $InlinevoidRead () {Panax Notoginsengscanf"%LF%LF%*LF", &x, &y); - } the } A[n], b[n]; + A intN, M; the intDis[n][n]; + - BOOLIn_one_line (P x, p y) { $ inti; $ if(x.x >y.x) Swap (x, y); - for(i =1; I <= m; ++i) - if(b[i].x < x.x | | b[i].x > y.x)return 0; the if(X.y >y.y) Swap (x, y); - for(i =1; I <= m; ++i)Wuyi if(B[i].y < x.y | | b[i].y > Y.Y)return 0; the return 1; - } Wu - intCheck (P x, p y) { About intI, Cnt1, Cnt2; $ LF tmp; - for(i =1, cnt1 = Cnt2 =0; I <= m; ++i) { -TMP = (y-x) * (B[i]-x); - if(tmp > EPS) + +cnt1; A if(TMP <-EPS) + +Cnt2; + if(Cnt1 && Cnt2)return 0; the } - if(!cnt1 &&!cnt2 &&in_one_line (x, y)) { $Puts"2"); the return-1; the } the returnCnt1?1: Cnt2?2:3; the } - in voidFloyd () { the intAns =inf, I, J, K; the for(k =1; K <= N; ++k) About for(i =1; I <= N; ++i) the for(j =1; J <= N; ++j) theDis[i][j] = min (Dis[i][j], dis[i][k] +dis[k][j]); the for(i =1; I <= N; ++i) +Ans =min (ans, dis[i][i]); - if(ans = = inf | | ans <=2) puts ("-1"); the Elseprintf"%d\n", ans);Bayi } the the voidsolve () { - intI, J, F; - for(i =1; I <= N; ++i) the for(j =1; J <= N; ++j) theDIS[I][J] =inf; the for(i =1; I <= N; ++i) the for(j = i +1; J <= N; ++j) { -f =Check (A[i], a[j]); the if(f = =-1)return; the if(f = =1) Dis[i][j] =1; the Else if(f = =2) Dis[j][i] =1;94 Else if(f = =3) Dis[i][j] = dis[j][i] =1; the } the Floyd (); the }98 About BOOLSpecial_judge () { - inti;101 for(i =1; I <= N; ++i)102 if(a[1]! = A[i])return 0;103 for(i =1; I <= m; ++i)104 if(a[1]! = B[i])return 0; thePuts"1");106 return 1;107 }108 109 intMain () { the inti;111scanf"%d%d", &n, &m); the for(i =1; I <= N; ++i)113 A[i].read (); the for(i =1; I <= m; ++i) the B[i].read (); the if(Special_judge ())return 0;117 solve ();118 return 0;119}
View Code
BZOJ1027 [JSOI2007] Alloy