poj 3304 Segments

来源:互联网 发布:免费的招聘软件 编辑:程序博客网 时间:2024/06/05 03:22
#include <iostream>
#include <string.h>
#include <cstdio>
#include <stdlib.h>
#include <algorithm>


using namespace std;
#define MAXN 222
#define eps 1e-8


int sid( double a)
{
    if(a > eps)
     return 1;
    if(a > -eps && a < eps)
     return 0;
    if(a < -eps)
     return -1;
}


struct Point
{
    double x, y;
    Point (){};
    Point ( double a, double b)
    {
        x = a;
        y = b;
    }
}p[MAXN];
int n;
double Across( Point a, Point b, Point c)
{
    return (b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x);
}


void solve( )
{
    bool flag = true;
    for( int i = 1; i <= 2*n; i++)
    {
        for(int j = i+1; j <= 2*n; j++)
        {
            flag = true;
            //printf("%lf  --- > %lf\n", p[i].x - p[j].x, p[i].y - p[j].y);
            if(sid(p[i].x - p[j].x) == 0 && sid(p[i].y - p[j].y) == 0)
                continue;
            for( int k = 1; k < 2*n; k += 2)
            {
                int d1 = sid(Across(p[i], p[j], p[k]));
                int d2 = sid(Across(p[i], p[j], p[k+1]));
               // printf("%d   ---0000-->   %d\n",d1, d2);
                if(d1*d2 > 0)
                 {
                     flag = false;
                     break;
                 }
            }
            if(flag)
            {
                printf("Yes!\n");
                return ;
            }
        }
    }
    printf("No!\n");
    return ;
}
int main()
{
   int t;
   scanf("%d",&t);
   while(t--)
   {
       scanf("%d",&n);
       for( int i = 1; i <= 2* n; i++)
         scanf("%lf %lf",&p[i].x, &p[i].y);
       solve( );
   }


}
0 0
原创粉丝点击