程设作业(合成矩形)

来源:互联网 发布:此何以知 编辑:程序博客网 时间:2024/05/17 10:53

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 input241 1 1 1 1 2 2 241 1 2 2 10 10 20 20sample outputYesNo

答案:

#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;}
0 0
原创粉丝点击