【hihocoder1255 2015北京赛区G】【简单模拟 简化写法超棒哦】 Mysterious Antiques in Sackler Museum 四个矩形选三个 恰好拼成大矩形

来源:互联网 发布:java ycad 编辑:程序博客网 时间:2024/05/29 16:25
#include<stdio.h>#include<string.h>#include<ctype.h>#include<math.h>#include<iostream>#include<string>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}const int N=0,M=0,Z=1e9+7,ms63=1061109567;int casenum,casei;int a[4][2];int b[4];bool check(int x,int y,int z){for(int i=0;i<2;i++){for(int j=0;j<2;j++){for(int k=0;k<2;k++){if(a[x][i]==a[y][j]&&a[x][i]==a[z][k])return 1;if(a[x][i]==a[y][j]+a[z][k]&&a[y][j^1]==a[z][k^1])return 1;}}}return 0;}int main(){scanf("%d",&casenum);for(casei=1;casei<=casenum;casei++){for(int i=0;i<4;i++)scanf("%d%d",&a[i][0],&a[i][1]);bool flag=0;for(int i=0;i<4;i++)b[i]=i;do{if(check(b[0],b[1],b[2])){flag=1;break;}}while(next_permutation(b,b+4));puts(flag?"Yes":"No");}return 0;}/*【trick&&吐槽】HDU7队竟然被这题卡了3个多小时然后打铁=.=他们平时做比赛还是有铜~银的实力的……  可见读题的重要性【题意】给你四个矩形,让你选出三个,并判断这三个矩形是否能恰好构成一个大的矩形【类型】模拟【分析】第一种构造法:左中右,即1*3第二种构造法:左+(卡)两种方法搞一下即可。简化写法更好写更方便哦~*/


下面是笨拙一点的写法——

#include<stdio.h>#include<string.h>#include<ctype.h>#include<math.h>#include<iostream>#include<string>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}const int N=0,M=0,Z=1e9+7,ms63=1061109567;int casenum,casei;struct A{int h,w;}a[4];bool ok(int len,A a,A b){if(len==a.h+b.h&&a.w==b.w)return 1;if(len==a.h+b.w&&a.w==b.h)return 1;if(len==a.w+b.h&&a.h==b.w)return 1;if(len==a.w+b.w&&a.h==b.h)return 1;return 0;}bool check(A a,A b,A c){//第一种构造法:左中右,即1*3if(a.h==b.h&&a.h==c.h)return 1;if(a.h==b.h&&a.h==c.w)return 1;if(a.h==b.w&&a.h==c.h)return 1;if(a.h==b.w&&a.h==c.w)return 1;if(a.w==b.h&&a.w==c.h)return 1;if(a.w==b.h&&a.w==c.w)return 1;if(a.w==b.w&&a.w==c.h)return 1;if(a.w==b.w&&a.w==c.w)return 1;//第二种构造法:左+(卡)if(ok(a.h,b,c))return 1;if(ok(a.w,b,c))return 1;if(ok(b.h,a,c))return 1;if(ok(b.w,a,c))return 1;if(ok(c.h,a,b))return 1;if(ok(c.w,a,b))return 1;return 0;}int main(){scanf("%d",&casenum);for(casei=1;casei<=casenum;casei++){for(int i=0;i<4;i++)scanf("%d%d",&a[i].h,&a[i].w);puts(check(a[1],a[2],a[3])||check(a[0],a[2],a[3])||check(a[0],a[1],a[3])||check(a[0],a[1],a[2])?"Yes":"No");}return 0;}/*【trick&&吐槽】HDU7队竟然被这题卡了3个多小时然后打铁=.=他们平时做比赛还是有铜~银的实力的……  可见读题的重要性【题意】给你四个矩形,让你选出三个,并判断这三个矩形是否能恰好构成一个大的矩形【类型】模拟【分析】第一种构造法:左中右,即1*3第二种构造法:左+(卡)两种方法搞一下即可。*/


1 0
原创粉丝点击