背景:这道题ac的时候我是不由自主的仰天长啸啊!!一直WA,WA了十多个小时,我真的不知道错在哪里了,索性搜
索别人的解题报告。最后最主要的是借鉴了排序思想。
思路:先将六组数据在横向进行排序,大的在左边,然后就对相同的数据进行合并,如果可以组成长方体,那么六组rectangular合并之后一定是三组。对于这三组数据进行纵向
的结构体排序,x大的靠上,如果x相等那么就以看y,y大的考上。这样排序之后就得到这样的关系:
然后根据简单的数学证明就可以得到:只有X1==X2&&y2==y3&&y1==x3时,才满足!
学习:1.sort的功能很强大!!对结构体进行排序,写cmp函数要严重借鉴!
</pre><pre name="code" class="cpp">struct a str[3];
sort(str,str+3,cmp);
2.这道题再次告诉我,没有把一道题思考的毫无逻辑漏洞就不要动笔!
3.应该把结构体定义放在所有自定义函数之前,如果不是,那么就会编译出错!
4记住:
#include<stdlib.h>
typedef struct {
int x;
int y;
}d;
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct rectangular{
int x;
int y;
}str[6],ans[3];
bool cmp(struct rectangular n,struct rectangular m);
bool cmp(struct rectangular n,struct rectangular m){
if(n.x>m.x) return true;
if(n.x<m.x) return false;
if(n.y>=m.y) return true;
else return false;
}
int main(void){
l1: while(scanf("%d%d%d%d%d%d%d%d%d%d%d%d",&str[0].x,&str[0].y,&str[1].x,&str[1].y,&str[2].x,&str[2].y,&str[3].x,&str[3].y,&str[4].x,&str[4].y,&str[5].x,&str[5].y)!=EOF){
for(int i=0;i<6;i++){
if(str[i].x<str[i].y){
int temp=str[i].x;
str[i].x=str[i].y;
str[i].y=temp;
}
}
memset(ans,0,sizeof(ans));
for(int j=0,k=0;j<6;j++){
if(str[j].x){
bool ii=true;
for(int i=j+1;i<6;i++){
if(str[i].x==str[j].x&&str[i].y==str[j].y){
ans[k].x=str[j].x;
ans[k++].y=str[j].y;
str[j].x=0;
str[j].y=0;
str[i].x=0;
str[i].y=0;
ii=false;
break;
}
}
if(ii){
printf("IMPOSSIBLE\n");
goto l1;
}
}
}
sort(ans,ans+6,cmp);
bool ok=false;
if(ans[0].x==ans[1].x){
if(ans[0].y==ans[2].x&&ans[2].y==ans[1].y) ok=true;
}
if(ok) printf("POSSIBLE\n");
else printf("IMPOSSIBLE\n");
}
return 0;
}