POJ 1755 Triathlon [半平面交 线性规划]

Triathlon
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 6912   Accepted: 1790

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


题意:

3800: Saber VS Lancer

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 69  Solved: 25
[Submit][Status][Discuss]

Description

铁人三项是一种运动项目,和字面意思一样,是让铁做的人(?)去做三个项目,必须连续完成,而且全程讲求速度。第一项是游泳,第二项是骑自行车,第三项是跑步。现在所有选手的三个项目的速度都是已知的。但是这次比赛中,裁判可以任意选择每一个项目的路程长度(假设没有一项长度为0)。但是这样显然会影响比赛排名……有时她会按某种方式选择,使得一些个别的选手能赢得竞赛。

Input

首行为运动员的人数N (1 ≤ N ≤ 100,80%的数据中n<=20),以下N行,每行含3个整数,Vi, Ui 和Wi (1 ≤ Vi, Ui, Wi ≤ 10000),用空格隔开,表示各人3个项目的速度。 

Output

对于每个运动员,都用一行输出,假如裁判以某种方式选择的路程会使得他赢(即第一个冲线,同时抵达不算赢),则输出“Yes”,否则输出“No”  。

卡精度太恶心了...........................两个小时!!!
对着 http://blog.csdn.net/acm_cxlove/article/details/7883370 调了好久终于用自己的写法A掉了
设长度x,y,1 两人列不等式  得到ax+by+c>0然后用半平面交模拟高中线性规划的做法......
 
直线方程和向量配合起来用太神了,注意那个直线和直线方程求交点的方法abcLI
 
注意:
Yes和No不是全大写
if(sgn(f(C))!=sgn(f(D))&&sgn(f(C))!=0&&sgn(f(D))!=0) 因为交点在直线上是不行的 我也不知道为什么要这样瞎凑出来的
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int N=;
const double INF=1e9;
const double eps=1e-1;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
} inline int sgn(double x){
if(abs(x)<eps) return ;
else return x<?-:;
} struct Vector{
double x,y;
Vector(double a=,double b=):x(a),y(b){}
bool operator <(const Vector &a)const{
return sgn(x-a.x)<||(sgn(x-a.x)==&&sgn(y-a.y)<);
}
void print(){printf("%lf %lf\n",x,y);}
};
typedef Vector Point;
Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);}
Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==&&sgn(a.y-b.y)==;}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
double Len(Vector a){return sqrt(Dot(a,a));}
Vector Normal(Vector a){
return Vector(-a.y,a.x);//counterClockwise
};
struct Line{
Point s,t;
Line(){}
Line(Point a,Point b):s(a),t(b){}
};
bool isLSI(Line l1,Line l2){
Vector v=l1.t-l1.s,u=l2.s-l1.s,w=l2.t-l1.s;
return sgn(Cross(v,u))!=sgn(Cross(v,w));
}
Point LI(Line a,Line b){
Vector v=a.s-b.s,v1=a.t-a.s,v2=b.t-b.s;
double t=Cross(v2,v)/Cross(v1,v2);
return a.s+v1*t;
} void iniPolygon(Point p[],int &n,double inf){
n=;
p[++n]=Point(,);
p[++n]=Point(,inf);
p[++n]=Point(inf,inf);
p[++n]=Point(inf,);
}
Point t[N];int tn;
double a,b,c;
double f(Point p){return a*p.x+b*p.y+c;}
Point abcLI(Line l){
double u=abs(f(l.s)),v=abs(f(l.t));
return Point(l.s.x*v+l.t.x*u,l.s.y*v+l.t.y*u)/(u+v);
}
void CutPolygon(Point p[],int &n){
tn=;
Point C,D;
p[]=p[n];p[n+]=p[];
for(int i=;i<=n;i++){
C=p[i],D=p[i%n+];
if(sgn(f(C))>=) t[++tn]=C;
if(sgn(f(C))!=sgn(f(D))&&sgn(f(C))!=&&sgn(f(D))!=) t[++tn]=abcLI(Line(C,D));
//else{
// if(sgn(f(p[i-1]))>0) t[++tn]=abcLI(Line(p[i-1],p[i]));
// if(sgn(f(p[i+1]))>0) t[++tn]=abcLI(Line(p[i],p[i+1]));
//}
}
n=tn;for(int i=;i<=n;i++) p[i]=t[i];
} double PolygonArea(Point p[],int n){
double s=;
for(int i=;i<n;i++) s+=Cross(p[i]-p[],p[i+]-p[]);
return abs(s/);
}
struct Saber{
double a,b,c;
}s[N];
int n,m;
Point q[N];
bool solve(int id){
iniPolygon(q,m,INF);
q[]=q[];q[]=q[];
for(int i=;i<=n;i++) if(i!=id){
a=(s[id].a-s[i].a)/(s[id].a*s[i].a);//ax+by+c>0
b=(s[id].b-s[i].b)/(s[id].b*s[i].b);
c=(s[id].c-s[i].c)/(s[id].c*s[i].c);
if(sgn(a)==&&sgn(b)==&&sgn(c)<=) return false;
CutPolygon(q,m);
}
return sgn(PolygonArea(q,m));
} int main(int argc, const char * argv[]){
n=read();
for(int i=;i<=n;i++) s[i].a=read(),s[i].b=read(),s[i].c=read();
for(int i=;i<=n;i++) puts(solve(i)?"Yes":"No");
}
 
 
上一篇:js精要之对象属性


下一篇:vue分页效果