The main problem: to reach the target point at least through a few walls.
Topic Ideas: The cycle of violence, calculate the points (do not forget the Four corners) and the target point line through how many lines, the minimum value.
#include <cstdio>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#include<cstring>#include<vector>#include<queue>#defineINF 0x3f3f3f3f#defineMAX 100005using namespacestd;structnode{intX1,y1,x2,y2;} Point[max];intN;DoubleSx,sy;DoubleCross (DoubleX1,DoubleY1,DoubleX2,DoubleY2,DoubleX3,DoubleY3,DoubleX4,Doubley4) { DoubleA= (X1-X2) * (y1-y3)-(X1-X3) * (y1-y2); Doubleb= (X1-X2) * (Y1-Y4)-(x1-x4) * (y1-y2); returnA *b;}intAns (DoubleX1,DoubleY1,intPOS) { intsum=1; for(intI=3; i<=n+2; i++) { if(pos==i)Continue; if(Cross (X1,Y1,SX,SY,POINT[I].X1,POINT[I].Y1,POINT[I].X2,POINT[I].Y2) <=1e-Ten&& Cross (Point[i].x1,point[i].y1,point[i].x2,point[i].y2,x1,y1,sx,sy) <1e-Ten) Sum++; } returnsum;}voidSolve () {intminn=INF; Doublex1,y1; for(intI=1; i<=n+2; i++) {x1=point[i].x1; Y1=point[i].y1; intans=Ans (x1,y1,i); Minn=min (Ans,minn); X1=point[i].x2; Y1=Point[i].y2; Ans=Ans (x1,y1,i); Minn=min (Ans,minn); } printf ("Number of doors =%d\n", Minn);}intMain () { while(SCANF ("%d", &n)! =EOF) {point[1].x1=0; point[1].y1=0; point[1].x2= -; point[1].y2= -; point[2].x1= -; point[2].y1=0; point[2].x2=0; point[2].y2= -; for(intI=3; i<=n+2; i++) {scanf ("%d%d%d%d",&point[i].x1,&point[i].y1,&point[i].x2,&point[i].y2); } scanf ("%LF%LF",&sx,&Sy); Solve (); } return 0;}
View Code
POJ 1066 Treasure Hunt