class point{
public:
point(){}
point(int a,int b):x(a),y(b){}
int x,y;
};
class segment{
public:
segment(){}
segment(point a,point b):p1(a),p2(b){}
point p1,p2;
};
segment ss[500];
int n;
int sameside(point p1,point p2,segment s)
{
int a,b;
a=((p1.x-s.p1.x)*(s.p2.y-s.p1.y)-(p1.y-s.p1.y)*(s.p2.x-s.p1.x));
b=((p2.x-s.p1.x)*(s.p2.y-s.p1.y)-(p2.y-s.p1.y)*(s.p2.x-s.p1.x));
return a*b;
}
bool intersect(segment s1,segment s2) //端点也算相交
{
int sameside1,sameside2;
sameside1=sameside(s2.p1,s2.p2,s1);
sameside2=sameside(s1.p1,s1.p2,s2);
if(sameside1>0||sameside2>0) return false;
if(sameside1+sameside2<=0) return true;
}
int check(segment s)
{
int ret(0);
for(int i=0;i<n;i++)
if(intersect(s,ss[i]))
ret++;
return ret;
}
int main()
{
while(cin>>n){
int x1,x2,y1,y2;
for(int i=0;i<n;i++){
cin>>x1>>y1>>x2>>y2;
point p1(x1,y1),p2(x2,y2);
segment s(p1,p2);
ss[i]=s;
}
cin>>x1>>y1;
int sum(0);
point p(x1,y1);
for(int i=0;i<n;i++){
segment s1(p,ss[i].p1),s2(p,ss[i].p2);
int t1=check(s1);
int t2=check(s2);
int t=t1>t2?t1:t2;
if(t>sum)sum=t;
}
cout<<sum<<endl;
}
return 1;
}
The shooter is in a great problem. He is trapped in a 2D maze with a laser gun and can use it once. The gun is very powerful and the laser ray, it emanates can traverse infinite distance in its direction. In the maze the targets are some walls (Here this is line segments). If the laser ray touches any wall or intersects it, that wall will be destroyed and the ray will advance ahead. The shooter wants to know the maximum number of walls, he can destroy with a single shot. The shooter will never stand on a wall.
Input
The input file contains 100 sets which needs to be processed. The description of each set is given below:
Each set starts with a postive integer, N(1<=N<=500) the number of walls. In next few lines there will be 4*N integers indicating two endpoints of a wall in cartesian co-ordinate system. Next line will contain (x, y) the coordinates of the shooter. All coordinates will be in the range [-10000,10000].
Input is terminated by a case where N=0. This case should not be processed.
Output
For each set of input print the maximum number of walls, he can destroy by a single shot with his gun in a single line.