poj1755 triathlon

Triathlon
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 5758 Accepted: 1467

Description

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

铁人三项
题意为给出n个人的游泳,骑车,奔跑速度,问每一个人在任选的路程内能否完成第一名(时间最短,不能并列)

可以设游泳距离为1,骑车距离为x,奔跑距离为y,可以得出如果一个人要的第一名,则所用时间必须必其他人都少,则可以得出n-1个方程,相关联则可以得出n个半平面交,如果面积>0 则输出yes

code:
#include <iostream>
#include <stdio.h>
#include <math.h>
#define eps 1e-8
#define inf 1<<28
#define zero(a) fabs(a)<eps
using namespace std;
struct Point
{
    double x,y;
}p[1505],tp[1505],q[1505];
struct Node
{
    double u,v,w;
}z[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 idx)
{
    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==idx) continue;
        double a,b,c;
        a=(z[idx].u-z[i].u)/(z[idx].u*z[i].u);
        b=(z[idx].v-z[i].v)/(z[idx].v*z[i].v);
        c=(z[idx].w-z[i].w)/(z[idx].w*z[i].w);
        if(a==0&&b==0&&c<eps) return 0;
        Cut(a,b,c,p,cnt);
    }
    return !zero(Get_area(p,cnt));
}
int main()
{
    int n;
    while( scanf("%d",&n)!=EOF)
	{
        for(int i=0;i<n;i++)
            scanf("%lf%lf%lf",&z[i].u,&z[i].v,&z[i].w);
        for(int i=0;i<n;i++)
            puts(slove(n,i)?"Yes":"No");
    }
    return 0;
}









                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值