UVA 1587 - Box

题目大意:给6个面,每个面有长宽,问能否组成一个长方体。

解题思路:按长>宽的优先级排序,结果要求第一个与第二个,第三个与第四个,第五个与第六个面完全相同。且第一个面的长与第三个面的长相同,第一个面的宽与第五个面的长相同,第二个面的宽与第五个面的宽相同。

ac代码:

#include 
#include 
using namespace std;
struct node{
	int length;
	int weight;
}no[6];
int n, m, jud;
bool compare(node a, node b)
{
	if (a.length != b.length)
		return a.length > b.length;
	return a.weight > b.weight;
}
void convet(int i)
{
	if (n > m)
		no[i].length = n, no[i].weight = m;
	else
		no[i].length = m, no[i].weight = n;
}
int main()
{
	while (scanf("%d%d", &n, &m)!=EOF){
		jud = 1;
		convet(0);
		for (int i=1; i<6; i++){
			scanf("%d%d", &n, &m);
			convet(i);
		}
		sort(no, no+6, compare);	
		for (int i=0; i<6; i+=2)
			if (no[i].length != no[i+1].length 
			|| no[i].weight != no[i+1].weight)
				jud = 0;
		if (no[0].length != no[2].length 
		|| no[0].weight != no[4].length
		|| no[2].weight != no[4].weight)
			jud = 0;
		if (jud)
			printf("POSSIBLE\n");
		else
			printf("IMPOSSIBLE\n");	
	}
return 0;
} 

你可能感兴趣的:(#,其他,UVA)