Set out the $x,y,z$ three unknown quantity to represent three kinds of units of combat effectiveness respectively.
Then all kinds of inequalities can be expressed as $ax+by+cz\geq 0$ form.
Notice the $z>0$, then divide both sides by $z$ to get $ax+by+c\geq 0$.
Then after the half-plane intersection to find all vertices, all vertices are brought into the evaluation for each query.
#include <cstdio> #include <cmath> #include <algorithm>using namespace Std;const int N=400;const Double eps=1e-10;struct p{double x, y; P () {x=y=0;} P (double _x,double _y) {x=_x,y=_y;} P operator-(const p&a) Const{return P (X-A.X,Y-A.Y);} P operator+ (const p&a) Const{return P (X+A.X,Y+A.Y);} P operator* (double A) Const{return p (x*a,y*a);}} P[n],a[n];struct l{P p,v;double A; L () {} l (P _p,p _v) {p=_p,v=_v;} BOOL operator< (const L&B) Const{return A<B.A;} void Cal () {a=atan2 (v.y,v.x);}} Line[n],q[n];int N,m,cl,h,t;inline Double Cross (const p&a,const p&b) {return a.x*b.y-a.y*b.x;} The new half plane, in this vector a->b counterclockwise direction of the inline void newl (const p&a,const p&b) {line[++cl]=l (a,b-a);} inline bool Left (const P&p,const l&l) {return cross (L.V,P-L.P) >0;} Inline P pos (const l&a,const l&b) {P x=a.p-b.p;double t=cross (b.v,x)/cross (A.V,B.V); return a.p+a.v*t;} inline void Halfplane () {for (int i=1;i<=cl;i++) line[i].cal (); Sort (line+1,line+cl+1); H=t=1; Q[1]=LINE[1]; for (int i=2;i<=cl;i++) {while (H<t&&!left (P[t-1],line[i])) t--; while (H<t&&!left (p[h],line[i))) h++; if (Fabs (Q[T].V,LINE[I].V) <eps) Q[t]=left (Q[t].p,line[i])? Q[t]:line[i];else Q[++t]=line[i]; if (h<t) P[t-1]=pos (q[t],q[t-1]); } while (H<t&&!left (P[t-1],q[h])) t--; P[t]=pos (Q[t],q[h]);} int main () {NEWL (P (0,0), P (100,1)); NEWL (P (100,0), P (100,100)); NEWL (P (1,100), P (0,0)); NEWL (P (100,100), P (0,100)); NEWL (P (0.01,100), P (0.01,0)); NEWL (P (0,0.01), P (100,0.01)); scanf ("%d%d", &n,&m); while (n--) {char ch[5];int a,b,c,d,e,f; scanf ("%s", ch); if (ch[0]== ' J ') scanf ("%d%d%d%d%d%d", &a,&b,&c,&d,&e,&f); else scanf ("%d%d%d%d%d%d", &d,&e,&f,&a,&b,&c); A-=d,b-=e,c-=f; if (!a&&!b) continue; if (b) {P a=p (0,-1.0*c/b), b=p ( -100.0*a-c)/b), c=a; C.y+=1; if (c.x*a+c.y*b+c>0) Newl (A, b); else NEWL (b,a); }else{P a=p ( -1.0*c/a,0), B=p ( -1.0*c/a, +), c=a; C.x-=1; if (c.x*a+c.y*b+c>0) Newl (A, b); else NEWL (b,a); }} halfplane (); while (m--) {int a,b,c,d,e,f; scanf ("%d%d%d%d%d%d", &a,&b,&c,&d,&e,&f); A-=d,b-=e,c-=f; int flag=0; for (int i=h;i<=t;i++) {double tmp=p[i].x*a+p[i].y*b+c; if (tmp>-eps) flag|=1; if (tmp<eps) flag|=2; } if (Flag==1) puts ("J"); else if (flag==2) puts ("B"); Else puts ("U"); } return 0;}
BZOJ1829: [Usaco2010 mar]starc StarCraft