poj 2398 Toy Storage

http://poj.org/problem?id=2318是一样的;这里就不解释了;

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];
bool cmp( Node a , Node b )
{
   return a.x_upper < b.x_upper;    
}
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 );
        }    
        sort( point ,point + n ,cmp );
        int sum[5024] = {0};
        for( int i = 0; i < m ; i++ )
        {
           scanf( "%d %d",&x,&y ); 
           sum[Calculate( x,y ,n ,Y1 ,Y2)] ++;    
        }
        int count[5024]= {0};
        for( int i = 1 ; i <= n ; i ++ )
        {
            for( int j = 0; j <= n ; j ++ )
            if( sum[j] == i ) count[i] ++;    
        }
        puts( "Box" );
        for( int i = 1 ; i <= n ; i++ )
        {
            if( count[i] )
            printf( "%d: %d\n",i,count[i] );    
        }
    }
    //system( "pause" );
    return 0;
}

 

posted @ 2012-07-05 21:55  wutaoKeen  阅读(109)  评论(0编辑  收藏  举报