zoukankan      html  css  js  c++  java
  • Poj 1755Triathlon 未Ac,先mark

    地址:http://poj.org/problem?id=1755

    题目:

    Triathlon
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 6931   Accepted: 1797

    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

    思路:对于第i个人,时间可以表示为 ti=x/u[i]+y/v[i]+z/w[i]==>ti=ax+by+cz=>ti/z=ax+by+c(等式除以z,消去z)

      如果存在x,y使得i能赢,可以等价表示为 对于方程组 t[i]-t[j]<0有解

      ==>(ai-aj)x+(bi-bj)y+ci-cj<0

      所以可以用半平面交判断是否有解。

      另外因为可能解是一个不封闭区域,所以添加一个方框把解限制在第一象限内。

      把一般式转化成两点向量时总是错!!!

      暂时不想做了,先mark,日后再说。

    贴个未ac代码:

      1 #include <iostream>
      2 #include <cstdio>
      3 #include <cmath>
      4 #include <algorithm>
      5 
      6 
      7 using namespace std;
      8 const double eps = 1e-8;
      9 //
     10 class Point
     11 {
     12 public:
     13     double x, y;
     14 
     15     Point(){}
     16     Point(double x, double y):x(x),y(y){}
     17 
     18     bool operator < (const Point &_se) const
     19     {
     20         return x<_se.x || (x==_se.x && y<_se.y);
     21     }
     22     /*******判断ta与tb的大小关系*******/
     23     static int sgn(double ta,double tb)
     24     {
     25         if(fabs(ta-tb)<eps)return 0;
     26         if(ta<tb)   return -1;
     27         return 1;
     28     }
     29     static double xmult(const Point &po, const Point &ps, const Point &pe)
     30     {
     31         return (ps.x - po.x) * (pe.y - po.y) - (pe.x - po.x) * (ps.y - po.y);
     32     }
     33     friend Point operator + (const Point &_st,const Point &_se)
     34     {
     35         return Point(_st.x + _se.x, _st.y + _se.y);
     36     }
     37     friend Point operator - (const Point &_st,const Point &_se)
     38     {
     39         return Point(_st.x - _se.x, _st.y - _se.y);
     40     }
     41     //点位置相同(double类型)
     42     bool operator == (const Point &_off) const
     43     {
     44         return  Point::sgn(x, _off.x) == 0 && Point::sgn(y, _off.y) == 0;
     45     }
     46     //点位置不同(double类型)
     47     bool operator != (const Point &_Off) const
     48     {
     49         return ((*this) == _Off) == false;
     50     }
     51     //两点间距离的平方
     52     static double dis2(const Point &_st,const Point &_se)
     53     {
     54         return (_st.x - _se.x) * (_st.x - _se.x) + (_st.y - _se.y) * (_st.y - _se.y);
     55     }
     56     //两点间距离
     57     static double dis(const Point &_st, const Point &_se)
     58     {
     59         return sqrt((_st.x - _se.x) * (_st.x - _se.x) + (_st.y - _se.y) * (_st.y - _se.y));
     60     }
     61 };
     62 //两点表示的向量
     63 class Line
     64 {
     65 public:
     66     Point s, e;//两点表示,起点[s],终点[e]
     67     double a, b, c;//一般式,ax+by+c=0
     68 
     69     Line(){}
     70     Line(const Point &s, const Point &e):s(s),e(e){}
     71     Line(double _a,double _b,double _c):a(_a),b(_b),c(_c){}
     72 
     73     //向量与点的叉乘,参数:点[_Off]
     74     //[点相对向量位置判断]
     75     double operator /(const Point &_Off) const
     76     {
     77         return (_Off.y - s.y) * (e.x - s.x) - (_Off.x - s.x) * (e.y - s.y);
     78     }
     79     //向量与向量的叉乘,参数:向量[_Off]
     80     friend double operator /(const Line &_st,const Line &_se)
     81     {
     82         return (_st.e.x - _st.s.x) * (_se.e.y - _se.s.y) - (_st.e.y - _st.s.y) * (_se.e.x - _se.s.x);
     83     }
     84     friend double operator *(const Line &_st,const Line &_se)
     85     {
     86         return (_st.e.x - _st.s.x) * (_se.e.x - _se.s.x) - (_st.e.y - _st.s.y) * (_se.e.y - _se.s.y);
     87     }
     88     //从两点表示转换为一般表示
     89     //a=y2-y1,b=x1-x2,c=x2*y1-x1*y2
     90     bool pton()
     91     {
     92         a = e.y - s.y;
     93         b = s.x - e.x;
     94         c = e.x * s.y - e.y * s.x;
     95         return true;
     96     }
     97 
     98     //-----------点和直线(向量)-----------
     99     //点在向量左边(右边的小于号改成大于号即可,在对应直线上则加上=号)
    100     //参数:点[_Off],向量[_Ori]
    101     friend bool operator<(const Point &_Off, const Line &_Ori)
    102     {
    103         return (_Ori.e.y - _Ori.s.y) * (_Off.x - _Ori.s.x)
    104             < (_Off.y - _Ori.s.y) * (_Ori.e.x - _Ori.s.x);
    105     }
    106 
    107     //点在直线上,参数:点[_Off]
    108     bool lhas(const Point &_Off) const
    109     {
    110         return Point::sgn((*this) / _Off, 0) == 0;
    111     }
    112     //点在线段上,参数:点[_Off]
    113     bool shas(const Point &_Off) const
    114     {
    115         return lhas(_Off)
    116             && Point::sgn(_Off.x - min(s.x, e.x), 0) > 0 && Point::sgn(_Off.x - max(s.x, e.x), 0) < 0
    117             && Point::sgn(_Off.y - min(s.y, e.y), 0) > 0 && Point::sgn(_Off.y - max(s.y, e.y), 0) < 0;
    118     }
    119 
    120     //点到直线/线段的距离
    121     //参数: 点[_Off], 是否是线段[isSegment](默认为直线)
    122     double dis(const Point &_Off, bool isSegment = false)
    123     {
    124         ///化为一般式
    125         pton();
    126 
    127         //到直线垂足的距离
    128         double td = (a * _Off.x + b * _Off.y + c) / sqrt(a * a + b * b);
    129 
    130         //如果是线段判断垂足
    131         if(isSegment)
    132         {
    133             double xp = (b * b * _Off.x - a * b * _Off.y - a * c) / ( a * a + b * b);
    134             double yp = (-a * b * _Off.x + a * a * _Off.y - b * c) / (a * a + b * b);
    135             double xb = max(s.x, e.x);
    136             double yb = max(s.y, e.y);
    137             double xs = s.x + e.x - xb;
    138             double ys = s.y + e.y - yb;
    139             if(xp > xb + eps || xp < xs - eps || yp > yb + eps || yp < ys - eps)
    140                 td = min(Point::dis(_Off,s), Point::dis(_Off,e));
    141         }
    142 
    143         return fabs(td);
    144     }
    145 
    146     //关于直线对称的点
    147     Point mirror(const Point &_Off) const
    148     {
    149         ///注意先转为一般式
    150         Point ret;
    151         double d = a * a + b * b;
    152         ret.x = (b * b * _Off.x - a * a * _Off.x - 2 * a * b * _Off.y - 2 * a * c) / d;
    153         ret.y = (a * a * _Off.y - b * b * _Off.y - 2 * a * b * _Off.x - 2 * b * c) / d;
    154         return ret;
    155     }
    156     //计算两点的中垂线
    157     static Line ppline(const Point &_a, const Point &_b)
    158     {
    159         Line ret;
    160         ret.s.x = (_a.x + _b.x) / 2;
    161         ret.s.y = (_a.y + _b.y) / 2;
    162         //一般式
    163         ret.a = _b.x - _a.x;
    164         ret.b = _b.y - _a.y;
    165         ret.c = (_a.y - _b.y) * ret.s.y + (_a.x - _b.x) * ret.s.x;
    166         //两点式
    167         if(std::fabs(ret.a) > eps)
    168         {
    169             ret.e.y = 0.0;
    170             ret.e.x = - ret.c / ret.a;
    171             if(ret.e == ret. s)
    172             {
    173                 ret.e.y = 1e10;
    174                 ret.e.x = - (ret.c - ret.b * ret.e.y) / ret.a;
    175             }
    176         }
    177         else
    178         {
    179             ret.e.x = 0.0;
    180             ret.e.y = - ret.c / ret.b;
    181             if(ret.e == ret. s)
    182             {
    183                 ret.e.x = 1e10;
    184                 ret.e.y = - (ret.c - ret.a * ret.e.x) / ret.b;
    185             }
    186         }
    187         return ret;
    188     }
    189 
    190     //------------直线和直线(向量)-------------
    191     //直线向左边平移t的距离
    192     Line& moveLine(double t)
    193     {
    194         Point of;
    195         of=Point(-(e.y-s.y),e.x-s.x);
    196         double dis=sqrt(of.x*of.x+of.y*of.y);
    197         of.x=of.x*t/dis,of.y=of.y*t/dis;
    198         s=s+of,e=e+of;
    199         return *this;
    200     }
    201     //直线重合,参数:直线向量[_st],[_se]
    202     static bool equal(const Line &_st, const Line &_se)
    203     {
    204         return _st.lhas(_se.e) && _se.lhas(_se.s);
    205     }
    206     //直线平行,参数:直线向量[_st],[_se]
    207     static bool parallel(const Line &_st,const Line &_se)
    208     {
    209         return Point::sgn(_st / _se, 0) == 0;
    210     }
    211     //两直线(线段)交点,参数:直线向量[_st],[_se],交点
    212     //返回-1代表平行,0代表重合,1代表相交
    213     static bool crossLPt(const Line &_st,const Line &_se,Point &ret)
    214     {
    215         if(Line::parallel(_st,_se))
    216         {
    217             if(Line::equal(_st,_se)) return 0;
    218             return -1;
    219         }
    220         ret = _st.s;
    221         double t = (Line(_st.s,_se.s)/_se)/(_st/_se);
    222         ret.x += (_st.e.x - _st.s.x) * t;
    223         ret.y += (_st.e.y - _st.s.y) * t;
    224         return 1;
    225     }
    226     //------------线段和直线(向量)----------
    227     //线段和直线交
    228     //参数:直线[_st],线段[_se]
    229     friend bool crossSL(const Line &_st,const Line &_se)
    230     {
    231         return Point::sgn((_st / _se.s) * (_st / _se.e) ,0) <= 0;
    232     }
    233 
    234     //------------线段和线段(向量)----------
    235     //判断线段是否相交(注意添加eps),参数:线段[_st],线段[_se]
    236     static bool isCrossSS(const Line &_st,const Line &_se)
    237     {
    238         //1.快速排斥试验判断以两条线段为对角线的两个矩形是否相交
    239         //2.跨立试验(等于0时端点重合)
    240         return
    241             max(_st.s.x, _st.e.x) >= min(_se.s.x, _se.e.x) &&
    242             max(_se.s.x, _se.e.x) >= min(_st.s.x, _st.e.x) &&
    243             max(_st.s.y, _st.e.y) >= min(_se.s.y, _se.e.y) &&
    244             max(_se.s.y, _se.e.y) >= min(_st.s.y, _st.e.y) &&
    245             Point::sgn((_st / Line(_st.s, _se.s)) * (_st / Line(_st.s, _se.e)), 0) <= 0 &&
    246             Point::sgn((_se / Line(_se.s, _st.s)) * (_se / Line(_se.s, _st.e)), 0) <= 0;
    247     }
    248 };
    249 class Polygon
    250 {
    251 public:
    252     const static int maxpn = 200;
    253     Point pt[maxpn];//点(顺时针或逆时针)
    254     int n;//点的个数
    255 
    256     Point& operator[](int _p)
    257     {
    258         return pt[_p];
    259     }
    260 
    261     //求多边形面积,多边形内点必须顺时针或逆时针
    262     double area() const
    263     {
    264         double ans = 0.0;
    265         for(int i = 0; i < n; i ++)
    266         {
    267             int nt = (i + 1) % n;
    268             ans += pt[i].x * pt[nt].y - pt[nt].x * pt[i].y;
    269         }
    270         return fabs(ans / 2.0);
    271     }
    272     //求多边形重心,多边形内点必须顺时针或逆时针
    273     Point gravity() const
    274     {
    275         Point ans;
    276         ans.x = ans.y = 0.0;
    277         double area = 0.0;
    278         for(int i = 0; i < n; i ++)
    279         {
    280             int nt = (i + 1) % n;
    281             double tp = pt[i].x * pt[nt].y - pt[nt].x * pt[i].y;
    282             area += tp;
    283             ans.x += tp * (pt[i].x + pt[nt].x);
    284             ans.y += tp * (pt[i].y + pt[nt].y);
    285         }
    286         ans.x /= 3 * area;
    287         ans.y /= 3 * area;
    288         return ans;
    289     }
    290     //判断点在凸多边形内,参数:点[_Off]
    291     bool chas(const Point &_Off) const
    292     {
    293         double tp = 0, np;
    294         for(int i = 0; i < n; i ++)
    295         {
    296             np = Line(pt[i], pt[(i + 1) % n]) / _Off;
    297             if(tp * np < -eps)
    298                 return false;
    299             tp = (fabs(np) > eps)?np: tp;
    300         }
    301         return true;
    302     }
    303     //判断点是否在任意多边形内[射线法],O(n)
    304     bool ahas(const Point &_Off) const
    305     {
    306         int ret = 0;
    307         double infv = 1e-10;//坐标系最大范围
    308         Line l = Line(_Off, Point( -infv ,_Off.y));
    309         for(int i = 0; i < n; i ++)
    310         {
    311             Line ln = Line(pt[i], pt[(i + 1) % n]);
    312             if(fabs(ln.s.y - ln.e.y) > eps)
    313             {
    314                 Point tp = (ln.s.y > ln.e.y)? ln.s: ln.e;
    315                 if(fabs(tp.y - _Off.y) < eps && tp.x < _Off.x + eps)
    316                     ret ++;
    317             }
    318             else if(Line::isCrossSS(ln,l))
    319                 ret ++;
    320         }
    321         return (ret % 2 == 1);
    322     }
    323     //凸多边形被直线分割,参数:直线[_Off]
    324     Polygon split(Line _Off)
    325     {
    326         //注意确保多边形能被分割
    327         Polygon ret;
    328         Point spt[2];
    329         double tp = 0.0, np;
    330         bool flag = true;
    331         int i, pn = 0, spn = 0;
    332         for(i = 0; i < n; i ++)
    333         {
    334             if(flag)
    335                 pt[pn ++] = pt[i];
    336             else
    337                 ret.pt[ret.n ++] = pt[i];
    338             np = _Off / pt[(i + 1) % n];
    339             if(tp * np < -eps)
    340             {
    341                 flag = !flag;
    342                 Line::crossLPt(_Off,Line(pt[i], pt[(i + 1) % n]),spt[spn++]);
    343             }
    344             tp = (fabs(np) > eps)?np: tp;
    345         }
    346         ret.pt[ret.n ++] = spt[0];
    347         ret.pt[ret.n ++] = spt[1];
    348         n = pn;
    349         return ret;
    350     }
    351 
    352 
    353     /** 卷包裹法求点集凸包,_p为输入点集,_n为点的数量 **/
    354     void ConvexClosure(Point _p[],int _n)
    355     {
    356         sort(_p,_p+_n);
    357         n=0;
    358         for(int i=0;i<_n;i++)
    359         {
    360             while(n>1&&Point::sgn(Line(pt[n-2],pt[n-1])/Line(pt[n-2],_p[i]),0)<=0)
    361                 n--;
    362             pt[n++]=_p[i];
    363         }
    364         int _key=n;
    365         for(int i=_n-2;i>=0;i--)
    366         {
    367             while(n>_key&&Point::sgn(Line(pt[n-2],pt[n-1])/Line(pt[n-2],_p[i]),0)<=0)
    368                 n--;
    369             pt[n++]=_p[i];
    370         }
    371         if(n>1)   n--;//除去重复的点,该点已是凸包凸包起点
    372     }
    373 //    /****** 寻找凸包的graham 扫描法********************/
    374 //    /****** _p为输入的点集,_n为点的数量****************/
    375 //    /**使用时需把gmp函数放在类外,并且看情况修改pt[0]**/
    376 //    bool gcmp(const Point &ta,const Point &tb)/// 选取与最后一条确定边夹角最小的点,即余弦值最大者
    377 //    {
    378 //        double tmp=Line(pt[0],ta)/Line(pt[0],tb);
    379 //        if(Point::sgn(tmp,0)==0)
    380 //            return Point::dis(pt[0],ta)<Point::dis(pt[0],tb);
    381 //        else if(tmp>0)
    382 //            return 1;
    383 //        return 0;
    384 //    }
    385 //    void graham(Point _p[],int _n)
    386 //    {
    387 //        int cur=0;
    388 //        for(int i=1;i<_n;i++)
    389 //            if(Point::sgn(_p[cur].y,_p[i].y)>0 || (Point::sgn(_p[cur].y,_p[i].y)==0 && Point::sgn(_p[cur].x,_p[i].x)>0))
    390 //                cur=i;
    391 //        swap(_p[cur],_p[0]);
    392 //        n=0,pt[n++]=_p[0];
    393 //        if(_n==1)   return;
    394 //        sort(_p+1,_p+_n,Polygon::gcmp);
    395 //        pt[n++]=_p[1],pt[n++]=_p[2];
    396 //        for(int i=3;i<_n;i++)
    397 //        {
    398 //            while(Point::sgn(Line(pt[n-2],pt[n-1])/Line(pt[n-2],_p[i]),0)<0)
    399 //                n--;
    400 //            pt[n++]=_p[i];
    401 //        }
    402 //    }
    403     //凸包旋转卡壳(注意点必须顺时针或逆时针排列)
    404     //返回值凸包直径的平方(最远两点距离的平方)
    405     double rotating_calipers()
    406     {
    407         int i = 1;
    408         double ret = 0.0;
    409         pt[n] = pt[0];
    410         for(int j = 0; j < n; j ++)
    411         {
    412             while(fabs(Point::xmult(pt[i+1],pt[j], pt[j + 1])) > fabs(Point::xmult(pt[i],pt[j], pt[j + 1])) + eps)
    413                 i = (i + 1) % n;
    414             //pt[i]和pt[j],pt[i + 1]和pt[j + 1]可能是对踵点
    415             ret = (ret, max(Point::dis(pt[i],pt[j]), Point::dis(pt[i + 1],pt[j + 1])));
    416         }
    417         return ret;
    418     }
    419 
    420     //凸包旋转卡壳(注意点必须逆时针排列)
    421     //返回值两凸包的最短距离
    422     double rotating_calipers(Polygon &_Off)
    423     {
    424         int i = 0;
    425         double ret = 1e10;//inf
    426         pt[n] = pt[0];
    427         _Off.pt[_Off.n] = _Off.pt[0];
    428         //注意凸包必须逆时针排列且pt[0]是左下角点的位置
    429         while(_Off.pt[i + 1].y > _Off.pt[i].y)
    430             i = (i + 1) % _Off.n;
    431         for(int j = 0; j < n; j ++)
    432         {
    433             double tp;
    434             //逆时针时为 >,顺时针则相反
    435             while((tp = Point::xmult(_Off.pt[i + 1],pt[j], pt[j + 1]) - Point::xmult(_Off.pt[i], pt[j], pt[j + 1])) > eps)
    436                 i = (i + 1) % _Off.n;
    437             //(pt[i],pt[i+1])和(_Off.pt[j],_Off.pt[j + 1])可能是最近线段
    438             ret = min(ret, Line(pt[j], pt[j + 1]).dis(_Off.pt[i], true));
    439             ret = min(ret, Line(_Off.pt[i], _Off.pt[i + 1]).dis(pt[j + 1], true));
    440             if(tp > -eps)//如果不考虑TLE问题最好不要加这个判断
    441             {
    442                 ret = min(ret, Line(pt[j], pt[j + 1]).dis(_Off.pt[i + 1], true));
    443                 ret = min(ret, Line(_Off.pt[i], _Off.pt[i + 1]).dis(pt[j], true));
    444             }
    445         }
    446         return ret;
    447     }
    448 
    449     //-----------半平面交-------------
    450     //复杂度:O(nlog2(n))
    451     //#include <algorithm>
    452     //半平面计算极角函数[如果考虑效率可以用成员变量记录]
    453     static double hpc_pa(const Line &_Off)
    454     {
    455         return atan2(_Off.e.y - _Off.s.y, _Off.e.x - _Off.s.x);
    456     }
    457     //半平面交排序函数[优先顺序: 1.极角 2.前面的直线在后面的左边]
    458     static bool hpc_cmp(const Line &l, const Line &r)
    459     {
    460         double lp = hpc_pa(l), rp = hpc_pa(r);
    461         if(fabs(lp - rp) > eps)
    462             return lp < rp;
    463         return Point::xmult(r.s,l.s, r.e) < -eps;
    464     }
    465     static int judege(const Line &_lx,const Line &_ly,const Line &_lz)
    466     {
    467         Point tmp;
    468         Line::crossLPt(_lx,_ly,tmp);
    469         return Point::sgn(Point::xmult(_lz.s,tmp,_lz.e),0);
    470     }
    471     //获取半平面交的多边形(多边形的核)
    472     //参数:向量集合[l],向量数量[ln];(半平面方向在向量左边)
    473     //函数运行后如果n[即返回多边形的点数量]为0则不存在半平面交的多边形(不存在区域或区域面积无穷大)
    474     int halfPanelCross(Line _Off[], int ln)
    475     {
    476         Line dequeue[maxpn];//用于计算的双端队列
    477         int i, tn, bot, top;
    478         sort(_Off, _Off + ln, hpc_cmp);
    479         //平面在向量左边的筛选
    480         for(i = tn = 1; i < ln; i ++)
    481             if(fabs(hpc_pa(_Off[i]) - hpc_pa(_Off[i - 1])) > eps)
    482                 _Off[tn ++] = _Off[i];
    483         ln = tn, n = 0, bot = 0, top = 1;
    484         dequeue[0] = _Off[0];
    485         dequeue[1] = _Off[1];
    486         for(i = 2; i < ln; i ++)
    487         {
    488             while(bot < top &&  Polygon::judege(dequeue[top],dequeue[top-1],_Off[i]) > 0)
    489                 top --;
    490             while(bot < top &&  Polygon::judege(dequeue[bot],dequeue[bot+1],_Off[i]) > 0)
    491                 bot ++;
    492             dequeue[++ top] = _Off[i];
    493         }
    494         while(bot < top && Polygon::judege(dequeue[top],dequeue[top-1],dequeue[bot]) > 0)
    495             top --;
    496         while(bot < top && Polygon::judege(dequeue[bot],dequeue[bot+1],dequeue[top]) > 0)
    497             bot ++;
    498         //计算交点(注意不同直线形成的交点可能重合)
    499         if(top <= bot + 1)
    500             return 0;
    501         return 1;
    502     }
    503 };
    504 
    505 Line ln[200];
    506 Polygon py;
    507 int n,u[100],v[100],w[100];
    508 
    509 
    510 int main(void)
    511 {
    512     scanf("%d",&n);
    513     for(int i=0;i<n;i++)
    514         scanf("%d%d%d",u+i,v+i,w+i);
    515     ln[0]=Line(Point(0,0),Point(1e10,0));
    516     ln[1]=Line(Point(0,1e10),Point(0,0));
    517     ln[2]=Line(Point(1e10,0),Point(1e10,1e10));
    518     ln[3]=Line(Point(1e10,1e10),Point(0,1e10));
    519     for(int i=0;i<n;i++)
    520     {
    521         int ff=0,k=4;
    522         for(int j=0;j<n;j++)
    523         if(j!=i)
    524         {
    525             //ax+by+c>0有解==>-ax-by-c<=0,半平面在向量左边
    526             double ta=(double)(u[i]-u[j])/(double)(u[i]*u[j]);
    527             double tb=(double)(v[i]-v[j])/(double)(v[i]*v[j]);
    528             double tc=(double)(w[i]-w[j])/(double)(w[i]*w[j]);
    529             if(u[i]==u[j]&&v[i]==v[j])
    530             {
    531                 if(Point::sgn(tc,0)>=0)
    532                 {
    533                     ff=1;break;
    534                 }
    535                 continue;
    536             }
    537             if(Point::sgn(ta,0)>0)
    538                 ln[k++]=Line(Point(-tc/ta,0),Point(-tc/ta-tb,ta));
    539             else if(Point::sgn(ta,0)==0)
    540                 ln[k++]=Line(Point(0,-tc/tb),Point(100,-ta-tc/tb));
    541             else
    542                 ln[k++]=Line(Point(-tc/ta,0),Point(-tc/ta+tb,-ta));
    543             //double tt=ta*ln[k-1].s.x+tb*ln[k-1].s.y+tc;
    544             //double tk=ta*ln[k-1].e.x+tb*ln[k-1].e.y+tc;
    545             //printf("%d:%d:%.2f %.2f
    ",i,j,tt,tk);
    546             //printf("%.2f %.2f %.2f->%.2f %.2f %.2f %.2f
    ",ta,tb,tc,ln[k-1].s.x,ln[k-1].s.y,ln[k-1].e.x,ln[k-1].e.y);
    547 
    548         }
    549         if(ff || !py.halfPanelCross(ln,k))
    550             printf("No
    ");
    551         else
    552             printf("Yes
    ");
    553     }
    554     return 0;
    555 }
  • 相关阅读:
    Ghost博客安装
    PHP变量作用域
    ssh文件传输命令:sz与rz命令
    excel怎么固定第一行
    memcache和redis区别
    Memcache分布式部署方案
    Memcache服务器端参数说明
    Memcache基础教程
    在Windows下安装Memcached
    MySQL体系结构和存储引擎概述
  • 原文地址:https://www.cnblogs.com/weeping/p/6383612.html
Copyright © 2011-2022 走看看