zoukankan      html  css  js  c++  java
  • 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=2005;
    const double INF=1e9;
    const double eps=1e-18;
    inline int read(){
        char c=getchar();int x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
        return x*f;
    }
    
    inline int sgn(double x){
        if(abs(x)<eps) return 0;
        else return x<0?-1:1;
    }
    
    struct Vector{
        double x,y;
        Vector(double a=0,double b=0):x(a),y(b){}
        bool operator <(const Vector &a)const{
            return sgn(x-a.x)<0||(sgn(x-a.x)==0&&sgn(y-a.y)<0);
        }
        void print(){printf("%lf %lf
    ",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)==0&&sgn(a.y-b.y)==0;}
    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=0;
        p[++n]=Point(0,0);
        p[++n]=Point(0,inf);
        p[++n]=Point(inf,inf);
        p[++n]=Point(inf,0);
    }
    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=0;
        Point C,D;
        p[0]=p[n];p[n+1]=p[1];
        for(int i=1;i<=n;i++){
            C=p[i],D=p[i%n+1];
            if(sgn(f(C))>=0) t[++tn]=C;
            if(sgn(f(C))!=sgn(f(D))&&sgn(f(C))!=0&&sgn(f(D))!=0) 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=1;i<=n;i++) p[i]=t[i];
    }
    
    double PolygonArea(Point p[],int n){
        double s=0;
        for(int i=2;i<n;i++) s+=Cross(p[i]-p[1],p[i+1]-p[1]);
        return abs(s/2);
    }
    struct Saber{
        double a,b,c;
    }s[N];
    int n,m;
    Point q[N];
    bool solve(int id){
        iniPolygon(q,m,INF);
        q[0]=q[4];q[5]=q[1];
        for(int i=1;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)==0&&sgn(b)==0&&sgn(c)<=0) return false;
            CutPolygon(q,m);
        }
        return sgn(PolygonArea(q,m));
    }
    
    int main(int argc, const char * argv[]){
        n=read();
        for(int i=1;i<=n;i++) s[i].a=read(),s[i].b=read(),s[i].c=read();
        for(int i=1;i<=n;i++) puts(solve(i)?"Yes":"No");
    }
     
     
  • 相关阅读:
    ASP.NET中常用的26个优化性能方法(转)
    代码整洁
    【在开发中常用的UI控件】
    【加法计算器--结果label不显示加值】
    【点击textfield的时候不出现键盘】
    【XCODE上的项目运行到模拟器上是一片空白】
    【xcode commit失败 please tell me who you are】
    【storyboard 上没有箭头的解决办法】
    【ios模拟器上没 home键,怎么返回的?】
    【这是一个JAVA开发者的博客~】
  • 原文地址:https://www.cnblogs.com/candy99/p/6359105.html
Copyright © 2011-2022 走看看