链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4462
code
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
struct Node
{
int w,h;
bool operator < ( const Node & node)
{
if(h == node.h) return w < node.w;
return h < node.h;
}
bool operator != ( const Node & node)
{
if(h != node.h || w != node.w) return true;
return false;
}
}a[10];
bool possible()
{
bool flag = true;
if(a[0] != a[1]) flag = false;
if(a[2] != a[3]) flag = false;
if(a[4] != a[5]) flag = false;
if(a[0].h != a[2].h) flag = false;
if(a[0].w != a[4].h) flag = false;
if(a[3].w != a[4].w) flag = false;
return flag;
}
int main()
{
int w,h;
while(scanf("%d %d",&w ,&h) == 2)
{
if(w < h) swap(w,h);
a[0].w = w;
a[0].h = h;
for( int i = 1 ; i < 6 ; i ++)
{
scanf("%d %d",&w ,&h);
if(w < h) swap(w,h);
a[i].w = w; a[i].h = h;
}
sort(a,a+6);
if(possible()) printf("POSSIBLE\n");
else printf("IMPOSSIBLE\n");
}
return 0;
}
1)在本题中借鉴了一个新的技巧——自定义对象并且重载运算符,大大简化了一部分比较的业务逻辑。
2)在possible函数的时候一开始只限定了有三对,忘记要比较相邻边要相等的条件导致WA