题目:
题目分析:暴力枚举水题。。。枚举出长方形,再枚举出各种搭配即可
代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define MAX 37
using namespace std;
int n;
struct point
{
int x,y;
bool operator < ( const point& a ) const
{
if ( x == a.x ) return y < a.y;
else return x < a.x;
}
}p[MAX];
struct rectangle
{
point p1,p2;
int area;
}r[MAX*MAX];
int mp[217][217];
int pattern ( int i , int j )
{
if ( r[i].p2.x < r[j].p1.x ) return 1;
if ( r[i].p2.y < r[j].p1.y ) return 1;
if ( r[i].p1.x > r[j].p2.x ) return 1;
if ( r[i].p1.y > r[j].p2.y ) return 1;
if ( r[i].p1.x < r[j].p1.x && r[i].p1.y < r[j].p1.y
&&r[i].p2.x > r[j].p2.x && r[i].p2.y > r[j].p2.y ) return 2;
else return 0;
}
int main ( )
{
while ( scanf ( "%d" , &n ) , n )
{
memset ( mp , 0 , sizeof ( mp ) );
for ( int i = 0 ; i < n ; i++ )
{
scanf ( "%d%d" , &p[i].x , &p[i].y );
mp[p[i].x][p[i].y] = 1;
}
sort ( p , p + n );
int cnt = 0;
for ( int i = 0 ; i < n ; i++ )
for ( int j = i+1 ; j < n ; j++ )
if ( p[j].x > p[i].x && p[j].y > p[i].y )
if ( mp[p[i].x][p[j].y] && mp[p[j].x][p[i].y] )
r[cnt].p1.x = p[i].x , r[cnt].p1.y = p[i].y,
r[cnt].p2.x = p[j].x , r[cnt].p2.y = p[j].y,
r[cnt++].area = ( p[j].x - p[i].x ) * ( p[j].y - p[i].y );
int ans = -1;
for ( int i = 0 ; i < cnt ; i++ )
for ( int j = 0 ; j < cnt ; j++ )
{
if ( pattern(i,j) == 1 )
ans = max ( ans , r[i].area + r[j].area );
else if ( pattern(i,j) == 2 )
ans = max ( ans , r[i].area );
}
if ( ans == -1 ) puts ( "imp" );
else printf ( "%d\n" , ans );
}
}