- 参考博客
题意:大概意思就是判断四个矩形能不能从中选取三个矩形组成一个大的矩形。
题解:- 从四个矩形中任选三个,这样有四种选法。
- 三个矩形能凑成一个矩形首先是两个矩形有一条边相等,第三个矩形要么有边跟他们相等的边相等,要么有边跟他们不相等的边的和相等(有点绕)。
想明白这两点之后直接暴力就可以了,当时训练赛的时候因为读错题然后一直WA烦躁一直没法静下心来想,修养不够,修养不够。
#include#include #include #include #include using namespace std;struct node{ int a,b;}s[5],tmp;node judge(node a,node b)/*这里返回结构体,这样可以减少好多代码,相当于两个矩形构成了一个新的矩形*/{ if(a.a==b.a) return (node){a.a,a.b+b.b}; if(a.b==b.a) return (node){a.b,a.a+b.b}; if(a.a==b.b) return (node){a.a,a.b+b.a}; if(a.b==b.b) return (node){a.b,a.a+b.a}; return (node){0,0};}int pd(node a,node b,node c){ tmp = judge(a,b); tmp = judge(tmp,c); if(tmp.a>0) return 1; tmp = judge(a,c); tmp = judge(tmp,b); if(tmp.a>0) return 1; tmp = judge(b,c); tmp = judge(tmp,a); if(tmp.a>0) return 1; return 0;}int main(){ int t,i; scanf("%d",&t); while(t--) { for(i=0;i<4;i++) scanf("%d%d",&s[i].a,&s[i].b); if(pd(s[0],s[1],s[2])) { printf("Yes\n"); continue; } if(pd(s[0],s[1],s[3])) { printf("Yes\n"); continue; } if(pd(s[0],s[2],s[3])) { printf("Yes\n"); continue; } if(pd(s[1],s[2],s[3])) { printf("Yes\n"); continue; } printf("No\n"); } return 0;}