题意:给出四个矩形的长,宽,问能否找到三个矩形拼成一个大矩形。
思路:枚举即可。两个小矩形能拼成大矩形的条件是有一个边的长度相等。先用两个去拼接 新矩形,用新的矩形和剩下的两个小矩形判断,是否相等的边!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <algorithm>
#include <stdlib.h>
#include <map>
using namespace std;
int data[4][2];
int main()
{
int test;
int len,wid;
bool flag;
int vis[4];
cin>>test;
while ( test-- ) {
memset( vis,0,sizeof(vis) ) ;
flag = false;
for ( int i=0;i<4; i++ ) cin>>data[i][0]>>data[i][1];
for ( int i=0; i<4; i++ )
{
vis[i] = 1;
len = data[i][0];
wid = data[i][1];
for ( int j=0; j<4; j++ )
{
if ( vis[j]==false )
{
if ( len==data[j][0] )
{
wid += data[j][1];
vis[j] = 1;
for ( int l = 0; l<4; l++ ) {
if ( vis[l]==false )
{
if ( len==data[l][0] || len==data[l][1] ||wid==data[l][0] ||wid==data[l][1] ) flag = 1;
}
}
vis[j] = 0 ;
wid -= data[j][1];
}
if ( len==data[j][1] )
{
wid += data[j][0];
vis[j] = 1;
for ( int l = 0; l<4; l++ ) {
if ( vis[l]==false )
{
if ( len==data[l][0] || len==data[l][1] ||wid==data[l][0] ||wid==data[l][1] ) flag = 1;
}
}
vis[j] = 0 ;
wid -= data[j][0];
}
if ( wid==data[j][0] )
{
len += data[j][1];
vis[j] = 1;
for ( int l = 0; l<4; l++ ) {
if ( vis[l]==false )
{
if ( wid==data[l][0] || wid==data[l][1] ||len==data[l][0] ||len==data[l][1] ) flag = 1;
}
}
vis[j] = 0 ;
len -= data[j][1];
}
if ( wid==data[j][1] )
{
len += data[j][0];
vis[j] = 1;
for ( int l = 0; l<4; l++ ) {
if ( vis[l]==false )
{
if ( wid==data[l][0] || wid==data[l][1] ||len==data[l][0] ||len==data[l][1] ) flag = 1;
}
}
vis[j] = 0 ;
len -= data[j][0];
}
}
}
vis[i] = 0 ;
}
if ( flag) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}