Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4145 | Accepted: 1708 |
Description
Input
Output
Sample Input
7 20 0 37 100 40 0 76 100 85 0 0 75 100 90 0 90 0 71 100 61 0 14 100 38 100 47 47 100 54.5 55.4
Sample Output
Number of doors = 2
Source
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef double mType; struct Tpoint { mType x,y; Tpoint(){} Tpoint(mType _x,mType _y):x(_x),y(_y){} }; struct Tsegment { Tpoint start,end; Tsegment(){} Tsegment(Tpoint _start,Tpoint _end):start(_start),end(_end){} Tsegment(mType sx,mType sy,mType ex,mType ey):start(sx,sy),end(ex,ey){} }; Tpoint MakeVector(Tpoint P,Tpoint Q) { return Tpoint(Q.x-P.x,Q.y-P.y); } mType CrossProduct(Tpoint P,Tpoint Q) { return P.x*Q.y-P.y*Q.x; } mType MultiCross(Tpoint P,Tpoint Q,Tpoint R) { return CrossProduct(MakeVector(Q,P),MakeVector(Q,R)); } bool IsIntersect(Tsegment P,Tsegment Q) { if(max(P.start.x,P.end.x)<min(Q.start.x,Q.end.x)|| max(P.start.y,P.end.y)<min(Q.start.y,Q.end.y)|| max(Q.start.x,Q.end.x)<min(P.start.x,P.end.x)|| max(Q.start.y,Q.end.y)<min(P.start.y,P.end.y))return 0; return (MultiCross(P.end,P.start,Q.start)*MultiCross(P.end,P.start,Q.end)<=0&& MultiCross(Q.end,Q.start,P.start)*MultiCross(Q.end,Q.start,P.end)<=0); } void test() { if(IsIntersect(Tsegment(0,0,1,1),Tsegment(0,1,0.5,0.5001)))puts("They are intersect!!"); else puts("No intersect!"); } Tsegment g[33]; mType a[4][66],X,Y; int m[4]; int i,j,k,n; void init(int x,int y) { if(!x)a[0][m[0]++]=y; if(!y)a[1][m[1]++]=x; if(x>=100)a[2][m[2]++]=y; if(y>=100)a[3][m[3]++]=x; } int solve(mType sx,mType sy) { Tsegment tmp=Tsegment(sx,sy,X,Y); int i,ret=0; for(i=0;i<n;++i) if(IsIntersect(g[i],tmp))++ret; return ret; } int main() { //test(); mType sx,sy,ex,ey,ee; int tmp,ans; while(~scanf("%d",&n)) { for(i=0;i<4;++i)a[i][0]=0,m[i]=1; for(i=0;i<n;++i) { scanf("%lf%lf%lf%lf",&sx,&sy,&ex,&ey); g[i]=Tsegment(sx,sy,ex,ey); init(sx,sy); init(ex,ey); } scanf("%lf%lf",&X,&Y); for(i=0;i<4;++i)a[i][m[i]++]=100; for(i=0;i<4;++i) sort(a[i],a[i]+m[i]); ans=n; for(i=0;i<4;++i) for(j=1;j<m[i];++j) { ee=(a[i][j]+a[i][j-1])/2.0; if(i==0)tmp=solve(0,ee); if(i==1)tmp=solve(ee,0); if(i==2)tmp=solve(100,ee); if(i==3)tmp=solve(ee,100); ans=min(ans,tmp); } printf("Number of doors = %d\n",ans+1); } return 0; }