poj 3335 Rotating Scoreboard

这是一道求凸多边形多核的问题;

View Code
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#include<cstring>

#include<vector>

#include<string>

#define LL long long

using namespace std;

class Point

{

public:

      double x,y;    

};

Point point[124],p[124],q[124];

double A,B,C;

void Get_line( Point a, Point b )

{

    A = b.y - a.y;

    B = a.x - b.x;

    C = b.x*a.y-a.x*b.y;    

}

Point Get_Point( Point a, Point b )

{

    Point ans;

    double u = fabs( a.x*A + a.y*B + C );

    double v = fabs( b.x*A + b.y*B + C );

    ans.x = ( a.x*v + b.x*u )/( u + v );

    ans.y = ( a.y*v + b.y*u )/( u + v );

    return ans;     

}

int Cut_Area( int n )

{

    int m = 0;

    for( int i = 1 ;i <= n ; i ++ )

    {

         if( p[i].x*A + p[i].y*B + C >=0 )

             q[++m] = p[i];

         else

         {

             if( p[i+1].x*A + p[i+1].y*B + C >0 )

                 q[++m] = Get_Point( p[i] , p[i+1] );             

             if( p[i-1].x*A + p[i-1].y*B + C >0 )

                 q[++m] = Get_Point( p[i] , p[i-1] );

         }    

    }

    for( int i = 1; i <= m ; i ++ )

         p[i] = q[i];

    p[m+1] = q[1];

    p[0] = q[m];

    return m;    

}

bool Solve( int n )

{

     int m = n;

     point[n+1] = point[1];

     for( int i = 1 ; i <= n+1 ; i ++ )

          p[i] = point[i];

     p[0] = p[n];

     for( int i = 1 ; i <= n ; i ++ )

     {

          Get_line( point[i], point[i+1] );

          m = Cut_Area( m );        

     }    

     if( m ==0  ) return false;

     else return true;

}

int main(  )

{

    int T,n;

    while( scanf( "%d",&T )==1 )

    {

        while( T-- )

        {

            scanf( "%d",&n );

            for( int i = 1 ; i <= n ;  i ++ )

                 scanf( "%lf%lf",&point[i].x,&point[i].y );

            if(Solve( n )) puts( "YES" );

            else puts( "NO" );

        }    

    }

    //system( "pause" );

    return 0;

}

 

你可能感兴趣的:(core)