Triathlon POJ

来源:互联网 发布:移动数据自动打开 编辑:程序博客网 时间:2024/05/16 23:41

Triathlon is an athletic contest consisting of three consecutive sections that should be completed as fast as possible as a whole. The first section is swimming, the second section is riding bicycle and the third one is running.

The speed of each contestant in all three sections is known. The judge can choose the length of each section arbitrarily provided that no section has zero length. As a result sometimes she could choose their lengths in such a way that some particular contestant would win the competition.
Input
The first line of the input file contains integer number N (1 <= N <= 100), denoting the number of contestants. Then N lines follow, each line contains three integers Vi, Ui and Wi (1 <= Vi, Ui, Wi <= 10000), separated by spaces, denoting the speed of ith contestant in each section.
Output
For every contestant write to the output file one line, that contains word “Yes” if the judge could choose the lengths of the sections in such a way that this particular contestant would win (i.e. she is the only one who would come first), or word “No” if this is impossible.
Sample Input
9
10 2 6
10 7 3
5 6 7
3 2 7
6 2 6
3 5 7
8 4 6
10 4 2
1 8 7
Sample Output
Yes
Yes
Yes
No
No
No
Yes
No
Yes

半平面交解不等式

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#define eps 1e-16#define inf 1<<28using namespace std;struct Point{    double x,y;}p[1505],tp[1505],q[1505];struct Node{    double u,v,w;}P[105];double xmul(Point p0,Point p1,Point p2){    return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);}Point Intersection(Point p1,Point p2,double a,double b,double c){    double u=fabs(a*p1.x+b*p1.y+c);    double v=fabs(a*p2.x+b*p2.y+c);    Point t;    t.x=(p1.x*v+p2.x*u)/(u+v);t.y=(p1.y*v+p2.y*u)/(u+v);    return t;}double Get_area(Point p[],int n){    double area=0;    for(int i=2;i<n;i++)        area+=xmul(p[1],p[i],p[i+1]);    return -area/2.0;}void Cut(double a,double b,double c,Point p[],int &cnt){    int tmp=0;    for(int i=1;i<=cnt;i++){        if(a*p[i].x+b*p[i].y+c>-eps) tp[++tmp]=p[i];        else{            if(a*p[i-1].x+b*p[i-1].y+c>eps)                tp[++tmp]=Intersection(p[i-1],p[i],a,b,c);            if(a*p[i+1].x+b*p[i+1].y+c>eps)                tp[++tmp]=Intersection(p[i],p[i+1],a,b,c);        }    }    for(int i=1;i<=tmp;i++)        p[i]=tp[i];    p[0]=p[tmp];p[tmp+1]=p[1];    cnt=tmp;}int slove(int n,int m){    p[1].x=0;p[1].y=0;    p[2].x=0;p[2].y=inf;    p[3].x=inf;p[3].y=inf;    p[4].x=inf;p[4].y=0;    p[0]=p[4];p[5]=p[1];    int cnt=4;    for(int i=0;i<n;i++){        if(i==m) continue;        double a,b,c;        a=(P[m].u-P[i].u)/(P[m].u*P[i].u);        b=(P[m].v-P[i].v)/(P[m].v*P[i].v);        c=(P[m].w-P[i].w)/(P[m].w*P[i].w);        if(a==0&&b==0&&c<eps) return 0;        Cut(a,b,c,p,cnt);    }    if (Get_area(p,cnt)>=eps)        return 1;    else        return 0;}int main(){    int n;    scanf("%d",&n);        for(int i=0;i<n;i++)            scanf("%lf%lf%lf",&P[i].u,&P[i].v,&P[i].w);        for(int i=0;i<n;i++)        printf("%s\n",slove(n,i)?"Yes":"No");    return 0;}
原创粉丝点击