CF_#322(Div.2) D. Three Logos(greedy)

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 yidetermine 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 nlines 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

题意:

给出三块矩形的大小,求是否能铺满一个正方形的区域。因为只有三个矩形,所以情况不会很多,而且题目说只需要输出任意一种满足情况的条件就可以。所以我们利用贪心的思想去填充区域,注意每次更新目标区域的起点坐标和终点坐标。

代码实现:

#include <bits/stdc++.h>

using namespace std;

const int MAX = 105;
struct node{
    int x,y;
    char tempo;
    friend bool operator < ( node a,node b ){
        if( a.x != b.x ){
            return a.x > b.x;
        }
        return a.y>b.y;
    }
};

int len;
int cnt;
bool flag;
node Lis[3];
char square[MAX][MAX];
char tag[3]={'A','B','C'};
void print();
int main()
{
    len = 0;
    cnt = 0;
    flag = true;
    for( int i = 0; i < 3; i++ ){
        int a,b;
        scanf("%d%d",&a,&b);
        if( a < b ){
            swap(a,b);
        }
        Lis[i].x = a;
        Lis[i].y = b;
        Lis[i].tempo = tag[i];
        len = max(len,a);
    }
    int x = len;
    int y = len;
    int px = 0;
    int py = 0;
    int tx = 0;
    int ty = 0;
    sort(Lis,Lis+3);
    for( int t = 0; t < 3; t++ ){
        if( Lis[t].x == x ){
            tx = px+Lis[t].x;
            ty = py+Lis[t].y;
            y -= Lis[t].y;
        }
        else if( Lis[t].x == y ){
            tx = px+Lis[t].y;
            ty = py+Lis[t].x;
            x -= Lis[t].y;
        }
        else if( Lis[t].y == y ){
            tx = px+Lis[t].x;
            ty = py+Lis[t].y;
            x -= Lis[t].x;
        }
        if( tx>len || ty>len ){
            flag = false;
            len = -1;
            break;
        }
        for( int i = py; i < ty; i++ ){
            for( int j = px; j < tx; j++ ){
                square[i][j] = Lis[t].tempo;
                cnt++;
            }
        }
        if( tx == len ){
            py = ty;
        }
        else{
            px = tx;
        }
        //printf("px:%d py:%d\n",px,py);
        //print();
    }
    if( cnt != len*len ){
        flag = false;
        len = -1;
    }
    printf("%d\n",len);
    print();
    return 0;
}

void print(){
    for( int i = 0; i < len; i++ ){
        for( int j = 0; j < len; j++ ){
            printf("%c",square[i][j]);
        }
        printf("\n");
    }
    return ;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值