程设作业(合成矩形)

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值