poj 2318 TOYS

这是一道计算几何题,这里用的是向量的叉积,由于隔板已经排好序了那么我们只要从左至右暴力过去可以了,条件是叉积大于0;

View Code
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#include<cstring>

#include<vector>

using namespace std;

class Node

{

public:

      int x_upper,x_lower;

};

Node point[5024];

int Calculate( int x, int y ,int n ,int Y1, int Y2 )

{

   int y1 = Y1 - Y2;

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

   {

        int x1 = point[i].x_upper - point[i].x_lower;

        int x2 = x - point[i].x_lower,y2 = y - Y2;

        if( x1 * y2 > y1 * x2 )

            return i;        

   }

   return n;    

}

int main(  )

{

    int n,m,X1,Y1,X2,Y2,x,y;

    while( scanf( "%d",&n ),n )

    {        

        scanf( "%d %d %d %d %d",&m,&X1,&Y1,&X2,&Y2 );

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

        {

              scanf( "%d %d",&point[i].x_upper , &point[i].x_lower );

        }    

        int sum[5024] = {0};

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

        {

           scanf( "%d %d",&x,&y ); 

           sum[Calculate( x,y ,n ,Y1 ,Y2)] ++;    

        }

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

        {

            printf( "%d: %d\n",i,sum[i] );    

        }

        puts( "" );

    }

    //system( "pause" );

    return 0;

}

 

你可能感兴趣的:(poj)