CCF CSP 201912-2 回收站选址
题目地址
#include <iostream>
#include <iomanip>
using namespace std;
#define N 100
typedef struct
{
int x;
int y;
} Point, * Ptr;
typedef Point ElemType;
int JudgeGarbagePoint ( Point* Points, int n, int i)
{
int k, relevants= 0 ;
for ( k= 0 ; k< n; k++ )
{
if ( Points[ k] . x== Points[ i] . x- 1 && Points[ k] . y== Points[ i] . y)
relevants++ ;
if ( Points[ k] . x== Points[ i] . x+ 1 && Points[ k] . y== Points[ i] . y)
relevants++ ;
if ( Points[ k] . x== Points[ i] . x&& Points[ k] . y== Points[ i] . y- 1 )
relevants++ ;
if ( Points[ k] . x== Points[ i] . x&& Points[ k] . y== Points[ i] . y+ 1 )
relevants++ ;
}
if ( relevants< 4 ) return - 1 ;
int score= 0 ;
for ( k= 0 ; k< n; k++ )
{
if ( Points[ k] . x== Points[ i] . x- 1 && Points[ k] . y== Points[ i] . y- 1 )
score++ ;
if ( Points[ k] . x== Points[ i] . x+ 1 && Points[ k] . y== Points[ i] . y+ 1 )
score++ ;
if ( Points[ k] . x== Points[ i] . x- 1 && Points[ k] . y== Points[ i] . y+ 1 )
score++ ;
if ( Points[ k] . x== Points[ i] . x+ 1 && Points[ k] . y== Points[ i] . y- 1 )
score++ ;
}
return score;
}
int main ( )
{
int n;
cin>> n;
int * Scores= new int [ n] ;
Point* Points= new Point[ n] ;
int x, y, i;
for ( i= 0 ; i< n; i++ )
{
cin>> x>> y;
Points[ i] . x= x, Points[ i] . y= y;
}
int results[ 5 ] = { 0 } ;
for ( i= 0 ; i< n; i++ )
{
int t= JudgeGarbagePoint ( Points, n, i) ;
if ( t!= - 1 ) results[ t] ++ ;
}
for ( i= 0 ; i< 5 ; i++ )
{
cout<< results[ i] << "\n" ;
}
return 0 ;
}
```