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