codeforces 581D Three Logos

Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area.

Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard.

Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules.
Input

The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively.
Output

If it is impossible to place all the three logos on a square shield, print a single integer “-1” (without the quotes).

If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters “A”, “B” or “C”. The sets of the same letters should form solid rectangles, provided that:

the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company,
the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company,
the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company, 

Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn’t have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them.

See the samples to better understand the statement.
Sample test(s)
Input

5 1 2 5 5 2

Output

5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC

Input

4 4 2 6 4 2

Output

6
BBBBBB
BBBBBB
AAAACC
AAAACC
AAAACC
AAAACC

题目大意:给你三个矩形的长宽,问你能否拼成一个正方形。能的话,输出该正方形的变长,以及实现的方案。
解题思路:先找出三个矩形中最长的边,那一定是正方形的边长。然后分类讨论,剩下两个矩形是水平重叠放置,还是竖直放置。如果两种情况都拼不成,则输出-1。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

typedef long long ll;
int a[3], b[3];
char ch[4] = {"ABC"};
char Gra[305][305];

int main() {
    int Max = 0, rec;
    for (int i = 0; i < 3; i++) {
        scanf("%d %d", &a[i], &b[i]);
        if (a[i] > b[i]) swap(a[i], b[i]);
        if (b[i] > Max) {
            Max = b[i];
            rec = i;
        }
    }

    for (int i = 0; i < a[rec]; i++) {
        for (int j = 0; j < Max; j++) {
            Gra[i][j] = ch[rec];
        }   
    }
    int flag = 1;
    int of = 0;
    int temp = a[rec];
    for (int i = 0; i < 3; i++) {
        if (i == rec) continue; 
        if (b[i] == Max && a[i] + a[rec] <= Max) {
            if (a[rec] != temp) {
                if (a[rec] + a[i] != Max) {
                    flag = 0;
                    break;
                }
            }
            for (int j = 0; j < a[i]; j++) {
                for (int k = 0; k < Max; k++) {
                    Gra[j + a[rec]][k] = ch[i];
                }   
            }   
            a[rec] += a[i];
        } else if (a[i] + a[rec] == Max && b[i] + of <= Max) {
            if (of) {
                if (of + b[i] != Max) {
                    flag = 0;
                    break;  
                }   
            }   
            for (int j = 0; j < a[i]; j++) {
                for (int k = 0; k < b[i]; k++) {
                    Gra[j + a[rec]][k + of] = ch[i];    
                }   
            }
            of = b[i];
        } else if (b[i] + a[rec] == Max && a[i] + of <= Max) {
            if (of) {
                if (of + a[i] != Max) {
                    flag = 0;
                    break;  
                }   
            }
            for (int j = 0; j < b[i]; j++) {
                for (int k = 0; k < a[i]; k++) {
                    Gra[j + a[rec]][k + of] = ch[i];    
                }   
            }   
            of = a[i];
        } else {
            flag = 0;
            break;
        }
    }
    if (flag) {
        printf("%d\n", Max);
        for (int i = 0; i < Max; i++) {
            for (int j = 0; j < Max; j++) {
                printf("%c", Gra[i][j]);    
            }puts("");
        }
    } else printf("-1\n");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值