• 全部
• 问答

# uva 比赛的E 题目？

jwd_1_cool 2003-07-29 10:21:05

input:
0 1 10 1
0 2 -10 2
0 0

...全文
10 点赞 收藏 12

12 条回复

jwd_1_cool 2003-08-01
ok!

jwd_1_cool 2003-08-01

2

standlove 2003-08-01

jwd_1_cool 2003-08-01

starfish 给出的想法：

------------------------------------------------------------

cygandti 2003-07-31
up

lymgf 2003-07-31

shooter: 0 0
wall1: -1 1 1 1
wall2: -2 2 2 2

1、给每个线段的端点赋一个计数值，初始为0，并求出每个线段的区间。
2、对每个区间，测试端点是否在区间内，若是，该端点计数加1。
3、最大计数值即为解

lymgf 2003-07-31
If the laser ray touches any wall or intersects it, that wall will be destroyed and the ray will advance ahead

-------------------------------------------------------------------------------

jwd_1_cool 2003-07-31

lymgf 2003-07-31

jwd_1_cool 2003-07-30

#include<iostream.h>
#include<string.h>

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;
}

jwd_1_cool 2003-07-30
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.

Sample Input Output for Sample Input
3 3
0 0 10 0 2
0 1 10 1
0 2 10 2
0 -1
3
0 0 10 0
0 1 10 1
0 3 10 3
0 2
0
--------------------------------------------------------------------------------

lymgf 2003-07-29

3.2w+

2003-07-29 10:21