POJ1755 Triathlon 半平面交

 利用半平面交判断不等式是否有解

Triathlon
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4489 Accepted: 1112

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

Source


#include<iostream>
#include<cmath>
#include<cstdio>
#include<complex>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cstdlib>

using namespace std;
#define max(a,b)  (a>b?a:b)
#define min(a,b)  (a<b?a:b)
#define eps 1e-16
#define zero(x)   (((x)>0?(x):-(x))<eps)
const double pi=acos(-1.0);
const double INF=0xFFFFFF;
struct point { double x,y; };
struct line { double a,b,c; };

#define MAXN  1500
int n,cut_count,cur_count;
point p[MAXN],tp[MAXN],que[MAXN];
line l[MAXN];



int sig(double k)
{
	if(fabs(k)<eps)
		return 0;
	return (k>0)?1:-1;
}

double xmult(point a,point b,point c)
{
	return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}

point intersect(point x,point y,line k)
{  
	point temp; 
    double u=fabs(k.a*x.x+k.b*x.y+k.c);  
    double v=fabs(k.a*y.x+k.b*y.y+k.c);
	temp.x=(x.x*v+y.x*u)/(u+v);
	temp.y=(x.y*v+y.y*u)/(u+v);
    return temp;
}  
 
void init()
{
	p[1].x=0,p[1].y=0;
	p[2].x=0,p[2].y=INF;
	p[3].x=p[3].y=INF;
	p[4].x=INF,p[4].y=0;
	p[0]=p[4];
	p[5]=p[1];
	for(int i=1;i<=n;i++)
		scanf("%lf%lf%lf",&l[i].a,&l[i].b,&l[i].c);
}

void initial()
{
	for(int i=1;i<=4;i++)
		tp[i]=p[i];
	tp[5]=tp[1];
	tp[0]=tp[4];
	cut_count=4;
}

bool cut(line edge)
{
	cur_count=0;
	if(edge.a==0 && edge.b==0 && edge.c==0)
		return false;
	for(int i=1;i<=cut_count;i++)
	{
		if(sig(edge.a*tp[i].x+edge.b*tp[i].y+edge.c)>0)
		{
			que[++cur_count]=tp[i];
		}
		else
		{
			if(sig(edge.a*tp[i-1].x+edge.b*tp[i-1].y+edge.c)>0)
			{
				que[++cur_count]=intersect(tp[i-1],tp[i],edge);
			
			}
			if(sig(edge.a*tp[i+1].x+edge.b*tp[i+1].y+edge.c)>0)
			{
				que[++cur_count]=intersect(tp[i+1],tp[i],edge);
			}
		}	
	}
	double area=0; 
	for(int i=1;i<=cur_count;i++)
		tp[i]=que[i];
	tp[cur_count+1]=que[1];
	tp[0]=tp[cur_count];
	cut_count=cur_count;
	for(int i=3;i<=cur_count;i++)
		area+=xmult(tp[1],tp[i-1],tp[i]); 
	area=fabs(area)/2;
	if(sig(area)==0)
		return false;
	return true; 
}

void half_panel_intersection(int index)
{
	line temp;
	initial();
	for(int i=1;i<=n;i++)
	{
		if(i==index)
			continue; 
		temp.a=(l[index].a-l[i].a)/(l[index].a*l[i].a); 
		temp.b=(l[index].b-l[i].b)/(l[index].b*l[i].b); 
		temp.c=(l[index].c-l[i].c)/(l[index].c*l[i].c);
		if(!cut(temp))
		{ 
			cout<<"No"<<endl;
			return;
		} 
	}
	cout<<"Yes"<<endl; 
}

int main() 
{
	cin>>n;
	init();
	for(int i=1;i<=n;i++)
		half_panel_intersection(i); 
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值