UVa——Box UVA - 1587

题解:

这道题目直接按照面与面之间的关系就可以判断出来了,比如样例一:

1345 2584
2584 683
2584 1345
683 1345
683 1345

2584 683

按照长到短的排序,得到以下样例

2584 1345
2584 1345
2584 683
2584 683
1345 683

1345 683

然后发现前4个长一定要相等,后4个短一定要相等,然后12的短和56的长一定要相等(想一想就证明到出来了)

代码就变得很简单了,只要写好结构体排序一下就行

#include <bits/stdc++.h>
using namespace std;

struct rec{
	int x,y;
	
	bool operator<(rec other) const{
		if(this->x != other.x) return this->x > other.x;
		else return this->y > other.y;
	}
}r[6];

int main() {
	//freopen("in.txt","r",stdin);
	
	while(scanf("%d%d",&r[0].x,&r[0].y) == 2){
		if(r[0].x < r[0].y) swap(r[0].x,r[0].y);
		for(int i = 1; i < 6; i++){
			scanf("%d%d",&r[i].x,&r[i].y);
			if(r[i].x < r[i].y) swap(r[i].x,r[i].y);
		}
		
		sort(r,r+6);
		
		int ok = 1;
		for(int i = 1; i < 4; i++){
			if((r[i].x != r[i-1].x) || (r[i+2].y != r[i+1].y)) ok = 0;
		}
		for(int i = 0; i < 2; i++){
			if(r[i].y != r[i+4].x) ok = 0;
		}
		if(ok) printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");

	}
	
	return 0;
}
PS:一开始楼主是用面的不同来做,但最后发现只是变复杂了orz,上面的方法还是一样要写

猜你喜欢

转载自blog.csdn.net/a673953508/article/details/80218015