Convex hull, Floyd to find the smallest ring.
First, the third variable can be obtained from the variable, so it can be omitted.
Then, if the product is in a convex bag made of raw materials, it can be synthesized.
So the problem is asking for the smallest convex hull that contains all the products.
So all the edges taken are on a certain side, so first determine which side can take, run Floyd the smallest ring can be.
#include <cstdio>#include<algorithm>#include<cstring>#include<cmath>#defineEPS 1e-10using namespacestd;Const intMAXN = -+Ten;Const intINF =0x3f3f3f3f;structPoint {Doublex, y; Point (Double_x=0,Double_y=0): X (_x), Y (_y) {}}MAT[MAXN],REQ[MAXN];structVector {Doublex, y; Double operator* (Vector b) {returnx*b.y-y*b.x;} Vector (Double_x=0,Double_y=0): X (_x), Y (_y) {} Vector (point A,point B): X (b.x-a.x), Y (b.y-a.y) {}};DoubleT;intSgnDoublex) {if(ABS (x) < EPS)return 0; Else if(x>0)return 1; Else return-1; }BOOLcheck_line (Point ls,point le,point p) {return(ls.x>p.x && le.x>p.x) | |(ls.x<p.x && le.x<p.x) | |(Ls.y>P.Y && le.y>p.y) | |(Ls.y<P.Y && le.y<p.y);} intG[MAXN][MAXN];intn,m;intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) scanf ("%LF%LF%LF",&mat[i].x,&mat[i].y,&t); for(intI=1; i<=m;i++) scanf ("%LF%LF%LF",&req[i].x,&req[i].y,&t); for(intI=1; i<=n;i++) { BOOLflag=true; for(intj=1; j<=m;j++) if(SGN (mat[i].x-req[j].x) | | SGN (MAT[I].Y-REQ[J].Y)) {flag=false; Break;} if(flag) {printf ("1\n", i);return 0;} } memset (G,0x3f,sizeof(g)); for(intI=1; i<=n;i++) for(intj=1; j<=n;j++)if(i!=j) { if(!SGN (mat[i].x-mat[j].x) &&!sgn (MAT[I].Y-MAT[I].Y))Continue; BOOLable=true; for(intk=1; k<=m;k++)if(SGN (Vector (Mat[i],mat[j]) *vector (Mat[i],req[k]) ==-1) {Able=false; Break; } if(able) { for(intk=1; k<=m;k++) if(SGN (Vector (Mat[i],mat[j]) *vector (mat[i],req[k]) = =0&&Check_line (Mat[i],mat[j],req[k])) {Able=false; Break; } } if(able) g[i][j]=1; } intres=inf; for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) for(intk=1; k<=n;k++) G[i][j]=min (g[i][j],g[i][k]+G[k][j]); for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) { if(i!=j) Res=min (res,g[i][j]+G[j][i]); Elseres=min (res,g[i][i]); } printf ("%d\n", res>n?-1: RES); return 0;}
bzoj1027: [JSOI2007] Alloy