Reference: https://www.cnblogs.com/zhuohan123/p/3237246.html
Because a C can be obtained by 1-a-b, the C is deleted, and a, B is abstracted to a point on a two-dimensional plane. First of all, consider what a customer needs can be the raw materials: two points on the line of raw materials can be, if a number of raw materials, then these lines of the vector of the convex hull points can be
So we get an n tripartite algorithm: Enumerate every two raw points, see if all the demand points are in the half plane of this vector, is even 1, then Floyd to find the smallest ring can
But there are a lot of nasty special sentences ...
1. Demand point coincident to a point
2. Where the demand points appear in the straight line of the two material points
#include <iostream>#include <cstdio>#include <cmath>using namespaceStdConst intn=505, inf=1e9;Const Doubleeps=1e-10;intM,n,a[n][n];DoubleCstructdian{Doublex, y; DianDoublex=0,Doubley=0) {x=x,y=y; } Dianoperator- (ConstDian &a)Const{returnDian (X-A.X,Y-A.Y); }}q[510],p[510];d Ian V (Dian A,dian b) {returnDian (B.X-A.X,B.Y-A.Y);}DoubleCJ (Dian A,dian b) {returnA.X*B.Y-B.X*A.Y;}BOOLOk (Dian S,dian T,dian p) {return! ((s.x>p.x&&t.x>p.x) | | (s.x<p.x&&t.x<p.x) | | (S.Y>P.Y&&T.Y>P.Y) | | (S.Y<P.Y&&T.Y<P.Y));}intMain () {scanf ("%d%d", &m,&n); for(intI=1; i<=m;i++) scanf ("%LF%LF%LF", &p[i].x,&p[i].y,&c); for(intI=1; i<=n;i++) scanf ("%LF%LF%LF", &q[i].x,&q[i].y,&c); for(intI=1; i<=m;i++) {BOOLflag=1; for(intj=1; j<=n;j++)if(ABS (p[i].x-q[j].x) >eps| | ABS (P[I].Y-Q[J].Y) >eps) flag=0;if(flag) {printf ("1\ n");return 0; } } for(intI=1; i<=m;i++) for(intj=1; j<=m;j++) A[i][j]=inf; for(intI=1; i<=m;i++) for(intj=1; j<=m;j++)if(I!=J) {if(ABS (p[i].x-p[j].x) <eps&&abs (P[I].Y-P[J].Y) <eps)Continue;intcan=1; for(intk=1; k<=n;k++)if(CJ (P[j]-p[i],q[k]-p[i]) <-eps) can=0;if(CAN) { for(intk=1; k<=n;k++) {DoubleCP=CJ (P[j]-p[i],q[k]-p[i]);if(cp<eps&&cp>-eps&& (!ok (p[i],p[j],q[k))) can=0; } }if(CAN) a[i][j]=1; }intAns=inf; for(intk=1; k<=m;k++) for(intI=1; i<=m;i++) for(intj=1; j<=m;j++)if(A[i][j]>a[i][k]+a[k][j]) a[i][j]=a[i][k]+a[k][j]; for(intI=1; i<=m;i++) for(intj=1; j<=m;j++) {if(I!=j&&a[i][j]+a[j][i]<ans) ans=a[i][j]+a[j][i];if(I==j&&a[i][j]<ans) ans=a[i][j]; } printf ("%d\n", Ans==inf?-1: ans);return 0;}
Bzoj 1027: [JSOI2007] alloy "convex bag +floyd"