题意:
给你四个矩形,判断能否从中选出3个组成一个矩形
思路:
1.搜索,如果两个能组成一个新的,则将他们合并,继续搜索
2.暴力判断
最开始没注意到3,一直以为要用4个,WR
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
const int maxn = 10005;
const int INF = 0x3f3f3f3f;
int x[5];
int y[5];
int vis[5];
int ans ;
void judge(int tx,int ty)
{
int num = 0;
if(ans == 1)
return;
for(int i = 0; i < 4; i++)
{
if(vis[i])
num ++;
}
if(num == 3)
{
ans = 1;
return ;
}
for(int i = 0; i < 4; i++)
{
if(!vis[i])
{
vis[i] = 1;
if(tx == x[i])
judge(tx,ty+y[i]);
else if(tx == y[i])
judge(tx,ty+x[i]);
else if(ty == y[i])
judge(tx + x[i],ty);
else if(ty == x[i])
judge(tx + y[i],ty);
vis[i] = 0;
}
}
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ans = 0;
memset(vis,0,sizeof(vis));
for(int i = 0; i < 4; i ++)
{
scanf("%d%d",&x[i],&y[i]);
}
for(int i = 0; i < 4; i++)
{
vis[i] = 1;
judge(x[i],y[i]);
vis[i] = 0;
if(ans == 1)
break;
}
if(ans == 1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}