uva1587 - Box

链接: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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值