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 Findequal(int origin, int *a, int num) {
int i, count = 0;
for (i = 0; i < num;) {
if (origin == a[i]) {
count++;
i = i + 2;
}
else if (origin != a[i])
++i;
}
return count;
}
int main(void) {
int T, i, j;
scanf("%d", &T);
while (T--) {
int N;
scanf("%d", &N);
int a[20] = {0};
for (i = 0; i < 2 * N; ++i)
scanf("%d", &a[i]);
for (i = 0; i < 2 * N; ++i) {
if (Findequal(a[i], a, N) >= 3) {
printf("Yes\n");
break;
}
else if (Findequal(a[i], a, N) == 2) {
for (j = 0; j < 2 * N; ++j) {
if (2 * a[i] == a[j]) {
printf("Yes\n");
break;
}
}
break;
}
}
if (i == 2 * N)
printf("No\n");
}
return 0;
}