rectangle(暴力求解)

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");
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值