Description:
Give you N rectangles.If you can pick exactly three pieces of those rectangles to form a larger rectangle?
input:
There are several testcases.
The first line is an integer T, indicating the number of testcases.
For each testcase:
The first line is a integer N and N is no more than 10.
The second line contains 2*N integers describing N rectangles.Each rectangle is described by 2 integers indicating as width and height.
All these integers in the second line are between [1,10000]
output
If you can do it, print Yes.Otherwise, print No instead.
sample input
2
4
1 1 1 1 1 2 2 2
4
1 1 2 2 10 10 20 20
sample output
Yes
No
#include<stdio.h>
int a[110][2][2];
int main() {
int T, n;
int i, j, k, x, y, z;
int flag;
scanf("%d", &T);
while (T--) {//不必使用for循环!
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d%d", &a[i][0][0], &a[i][0][1]);
a[i][1][0] = a[i][0][1];//0与1的取反,目的是方便后面的暴力求解
a[i][1][1] = a[i][0][0];
}
flag = 0;
for (i = 1; i <= n; i++) {
for (x = 0; x <= 1; x++)
for (j = 1; j <= n; j++) {
if (i == j) continue;
for (y = 0; y <= 1; y++)
for (k = 1; k <= n; k++) {
if (i == k || j == k) continue;
for (z = 0; z <= 1; z++) {
if (a[i][x][0] + a[j][y][0] == a[k][z][0]
&& a[i][x][1] == a[j][y][1]) flag = 1;
if (a[i][x][0] == a[j][y][0]
&& a[i][x][0] == a[k][z][0]) flag = 1;
}
}
}
}//暴力求解!
if (flag) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}