ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

codeforces581D

2019-04-22 20:43:51  阅读:393  来源: 互联网

标签:codeforces581D ch sizes logos should billboard logo


Three Logos

 CodeForces - 581D 

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 nuppercase 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.

Examples

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

sol:只有三个标记当然可以暴力模拟,就是判-1略微蛋疼
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0;
    bool f=0;
    char ch=' ';
    while(!isdigit(ch))
    {
        f|=(ch=='-'); ch=getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
    }
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0)
    {
        putchar('-'); x=-x;
    }
    if(x<10)
    {
        putchar(x+'0');    return;
    }
    write(x/10);
    putchar((x%10)+'0');
    return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=105;
int n=0,n1,n2,n3,m1,m2,m3;
char Map[N][N];
inline void OutPut()
{
    Wl(n);
    int i,j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++) putchar(Map[i][j]);
        putchar('\n');
    }
}
#define NO {puts("-1"); exit(0);}
inline void Judge()
{
    if(n*n!=(n1*m1+n2*m2+n3*m3)) NO
    if(n1==n&&n2==n&&n3==n) if(m1+m2+m3!=n) NO
    int i,j,c1=0,c2=0,c3=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(Map[i][j]=='A') c1++;
            else if(Map[i][j]=='B') c2++;
            else if(Map[i][j]=='C') c3++;
        }
    }
    if((c1!=n1*m1)||(c2!=n2*m2)||(c3!=n3*m3)) NO
}
int main()
{
    int i,j,Lastn,Lastm;
    R(n1); R(m1); R(n2); R(m2); R(n3); R(m3);
    if(n1<m1) swap(n1,m1); if(n2<m2) swap(n2,m2); if(n3<m3) swap(n3,m3);
    n=max(n1,max(m1,max(n2,max(m2,max(n3,m3)))));
    memset(Map,' ',sizeof Map);
    if(n1==n)
    {
        for(i=1;i<=n1;i++) for(j=1;j<=m1;j++) Map[i][j]='A';
        if(n2==n)
        {
            for(i=1;i<=n;i++) for(j=m1+1;j<=m1+m2;j++) Map[i][j]='B';
        }
        else
        {
            if(n2+m1==n) swap(n2,m2);
            for(i=1;i<=n2;i++) for(j=m1+1;j<=n;j++) Map[i][j]='B';
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(!isupper(Map[i][j])) Map[i][j]='C';
            }
        }
    }
    else if(n2==n)
    {
        for(i=1;i<=n2;i++) for(j=1;j<=m2;j++) Map[i][j]='B';
        if(n1==n)
        {
            for(i=1;i<=n;i++) for(j=m2+1;j<=m2+m1;j++) Map[i][j]='A';
        }
        else
        {
            if(n1+m2==n) swap(n1,m1);
            for(i=1;i<=n1;i++) for(j=m2+1;j<=n;j++) Map[i][j]='A';
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(!isupper(Map[i][j])) Map[i][j]='C';
            }
        }
    }
    else
    {
        for(i=1;i<=n3;i++) for(j=1;j<=m3;j++) Map[i][j]='C';
        if(n1==n)
        {
            for(i=1;i<=n;i++) for(j=m3+1;j<=m3+m1;j++) Map[i][j]='A';
        }
        else
        {
            if(n1+m3==n) swap(n1,m1);
            for(i=1;i<=n1;i++) for(j=m3+1;j<=n;j++) Map[i][j]='A';
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(!isupper(Map[i][j])) Map[i][j]='B';
            }
        }
    }
    Judge();
    OutPut();
    return 0;
}
/*
Input
5 1 5 2 5 2
Output
5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC

Input
4 4 2 6 4 2
Output
6
BBBBBB
BBBBBB
AAAACC
AAAACC
AAAACC
AAAACC

input
100 100 100 100 100 100
output
-1
*/
View Code

 

 

标签:codeforces581D,ch,sizes,logos,should,billboard,logo
来源: https://www.cnblogs.com/gaojunonly1/p/10752737.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有