poj 1755 Triathlon 半平面交

题意:在铁人三项比赛中,给出每个人游泳,骑车,跑步的速度,你可以任意安排游泳,骑车,跑步的路程(路程非0),若某人可以获得第一(严格),则输出Yes,否则No

 

思路:半平面交

固定一个项目的路程为1,另两个项目的路程为未知数x,y

对于每个人,依次判断其是否有可能为第一

每个人 建立n-1个方程 求半平面交  若有解 则Yes,否则No

 

 

 1 #include<iostream>
2 #include<cmath>
3 #include<cstring>
4 #include<vector>
5 #include<cstdio>
6 using namespace std;
7 #define INF 12345678
8 #define EPS 1e-8
9 #define MAXN 110
10 struct point
11 {
12 double x,y;
13 bool mark;
14 point(){}
15 point(double x0,double y0): x(x0),y(y0),mark(1){}
16 };
17 vector<point> p;
18 int n;
19 double a[MAXN],b[MAXN],c[MAXN];
20 point operator -(const point &A,const point &B)
21 {
22 return point(A.x-B.x,A.y-B.y);
23 }
24 double cross(point p1,point p2)
25 {
26 return p1.x*p2.y-p1.y*p2.x;
27 }
28 int dblcmp(double x)
29 {
30 if(fabs(x)<EPS) return 0;
31 return (x>0) ? 1:-1;
32 }
33 point find_intersection(point p1,point p2,point p3,point p4)
34 {
35 double s1=fabs(cross(p3-p1,p2-p1));
36 double s2=fabs(cross(p4-p1,p2-p1));
37 return point((p3.x*s2+p4.x*s1)/(s1+s2),(p3.y*s2+p4.y*s1)/(s1+s2));
38 }
39 void update(double A,double B,double C)
40 {
41 int i;
42 point temp;
43 for(i=0;i<p.size();i++)
44 {
45 if(dblcmp(A*p[i].x+B*p[i].y+C)>0) p[i].mark=1;
46 else p[i].mark=0;
47 }
48 p.push_back(p[0]);
49 for(i=0;i<p.size()-1;i++)
50 {
51 if(p[i].mark^p[i+1].mark==1)
52 {
53 if(A!=0)
54 temp=find_intersection(point(-C/A,0),point(-(B+C)/A,1),p[i],p[i+1]);
55 else if(B!=0)
56 temp=find_intersection(point(0,-C/B),point(1,-(A+C)/B),p[i],p[i+1]);
57 p.insert(p.begin()+i+1,temp);
58 i++;
59 }
60 }
61 p.pop_back();
62 for(i=0;i<p.size();i++)
63 if(p[i].mark==0)
64 p.erase(p.begin()+i), i--;
65 }
66
67 bool solve(int v)
68 {
69 int i;
70 for(i=1;i<=n;i++)
71 if(i!=v)
72 {
73 update(1/a[i]-1/a[v],1/b[i]-1/b[v],1/c[i]-1/c[v]);
74 if(p.size()==0) return 0;
75 }
76 return 1;
77 }
78 int main()
79 {
80 scanf("%d",&n);
81 int i;
82 for(i=1;i<=n;i++) scanf("%lf%lf%lf",a+i,b+i,c+i);
83 for(i=1;i<=n;i++)
84 {
85 p.clear();
86 p.push_back(point(INF,INF));
87 p.push_back(point(INF,0));
88 p.push_back(point(0,0));
89 p.push_back(point(0,INF));
90 if(solve(i)) printf("Yes\n");
91 else printf("No\n");
92 }
93 return 0;
94 }

 

 

 

 

 

 



posted on 2012-04-07 19:43  myoi  阅读(1164)  评论(0编辑  收藏  举报

导航