D. Three Logos

Time Limit: 1 Sec  

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/581/problem/D

Description

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 Input

5 1 2 5 5 2

Sample Output

5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC

HINT

 

题意

给你三个矩形,问你是否能拼成一个正方形

题解:

啊,能拼的就题目给你的样例的两种方式

那我们就都去尝试咯~

直接暴力枚举就好了,总共就2^3*6*2种搭配,都试试就好了……

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1205000
#define mod 1000000007
#define eps 1e-9
#define e exp(1.0)
#define PI acos(-1)
#define lowbit(x) (x)&(-x)
const double EP  = 1E-10 ;
int Num;
//const int inf=0x7fffffff;
const ll inf=999999999;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//*************************************************************************************

int a[300][300];
int check(int l1,int r1,int l2,int r2,int l3,int r3,int A,int B,int C)
{
    if(l1==l2&&l2==l3&&(r1+r2+r3)==l1)
    {
        cout<<l1<<endl;
        for(int i=1;i<=l1;i++)
            for(int j=1;j<=r1;j++)
                a[i][j]=A;
        for(int i=1;i<=l1;i++)
            for(int j=r1+1;j<=r1+r2;j++)
                a[i][j]=B;
        for(int i=1;i<=l1;i++)
            for(int j=r1+r2+1;j<=r1+r2+r3;j++)
                a[i][j]=C;
        for(int i=1;i<=l1;i++)
        {
            for(int j=1;j<=l2;j++)
            {
                if(a[i][j]==1)cout<<"A";
                else if(a[i][j]==2)cout<<"B";
                else cout<<"C";
            }
            cout<<endl;
        }
        return 1;
    }
    if(l2+l3!=l1)return 0;
    if(r1+r2!=l1)return 0;
    if(r2!=r3)return 0;
    for(int i=1;i<=l1;i++)
        for(int j=1;j<=r1;j++)
            a[i][j]=A;
    for(int i=1;i<=l2;i++)
        for(int j=r1+1;j<=r1+r2;j++)
            a[i][j]=B;
    for(int i=1;i<=l1;i++)
        for(int j=1;j<=l1;j++)
            if(a[i][j]==0)a[i][j]=C;
    cout<<l1<<endl;
    for(int i=1;i<=l1;i++)
    {
        for(int j=1;j<=l1;j++)
        {
            if(a[i][j]==1)cout<<"A";
            else if(a[i][j]==2)cout<<"B";
            else cout<<"C";
        }
        cout<<endl;
    }
    return 1;

}
int main()
{
    int l1,r1,l2,r2,l3,r3;
    int L1,R1,L2,R2,L3,R3;
    L1=read(),R1=read(),L2=read(),R2=read(),L3=read(),R3=read();
    //000 001 010 100 110 101 011 111
    //123 132 213 231 312 321
    //123
    l1=L1,r1=R1,l2=L2,r2=R2,l3=L3,r3=R3;
    if(check(l1,r1,l2,r2,l3,r3,1,2,3))return 0;
    if(check(l1,r1,l2,r2,r3,l3,1,2,3))return 0;
    if(check(l1,r1,r2,l2,r3,l3,1,2,3))return 0;
    if(check(r1,l1,l2,r2,l3,r3,1,2,3))return 0;
    if(check(r1,l1,r2,l2,l3,r3,1,2,3))return 0;
    if(check(r1,l1,l2,r2,r3,l3,1,2,3))return 0;
    if(check(l1,r1,r2,l2,r3,l3,1,2,3))return 0;
    if(check(r1,l1,r2,l2,r3,l3,1,2,3))return 0;
    //132
    l1=L1,r1=R1,l2=L3,r2=R3,l3=L2,r3=R2;
    if(check(l1,r1,l2,r2,l3,r3,1,3,2))return 0;
    if(check(l1,r1,l2,r2,r3,l3,1,3,2))return 0;
    if(check(l1,r1,r2,l2,r3,l3,1,3,2))return 0;
    if(check(r1,l1,l2,r2,l3,r3,1,3,2))return 0;
    if(check(r1,l1,r2,l2,l3,r3,1,3,2))return 0;
    if(check(r1,l1,l2,r2,r3,l3,1,3,2))return 0;
    if(check(l1,r1,r2,l2,r3,l3,1,3,2))return 0;
    if(check(r1,l1,r2,l2,r3,l3,1,3,2))return 0;
    //213
    l1=L2,r1=R2,l2=L1,r2=R1,l3=L3,r3=R3;
    if(check(l1,r1,l2,r2,l3,r3,2,1,3))return 0;
    if(check(l1,r1,l2,r2,r3,l3,2,1,3))return 0;
    if(check(l1,r1,r2,l2,r3,l3,2,1,3))return 0;
    if(check(r1,l1,l2,r2,l3,r3,2,1,3))return 0;
    if(check(r1,l1,r2,l2,l3,r3,2,1,3))return 0;
    if(check(r1,l1,l2,r2,r3,l3,2,1,3))return 0;
    if(check(l1,r1,r2,l2,r3,l3,2,1,3))return 0;
    if(check(r1,l1,r2,l2,r3,l3,2,1,3))return 0;
    //231
    l1=L2,r1=R2,l2=L3,r2=R3,l3=L1,r3=R1;
    if(check(l1,r1,l2,r2,l3,r3,2,3,1))return 0;
    if(check(l1,r1,l2,r2,r3,l3,2,3,1))return 0;
    if(check(l1,r1,r2,l2,r3,l3,2,3,1))return 0;
    if(check(r1,l1,l2,r2,l3,r3,2,3,1))return 0;
    if(check(r1,l1,r2,l2,l3,r3,2,3,1))return 0;
    if(check(r1,l1,l2,r2,r3,l3,2,3,1))return 0;
    if(check(l1,r1,r2,l2,r3,l3,2,3,1))return 0;
    if(check(r1,l1,r2,l2,r3,l3,2,3,1))return 0;
    //312
    l1=L3,r1=R3,l2=L1,r2=R1,l3=L2,r3=R2;
    if(check(l1,r1,l2,r2,l3,r3,3,1,2))return 0;
    if(check(l1,r1,l2,r2,r3,l3,3,1,2))return 0;
    if(check(l1,r1,r2,l2,r3,l3,3,1,2))return 0;
    if(check(r1,l1,l2,r2,l3,r3,3,1,2))return 0;
    if(check(r1,l1,r2,l2,l3,r3,3,1,2))return 0;
    if(check(r1,l1,l2,r2,r3,l3,3,1,2))return 0;
    if(check(l1,r1,r2,l2,r3,l3,3,1,2))return 0;
    if(check(r1,l1,r2,l2,r3,l3,3,1,2))return 0;

    //321
    l1=L3,r1=R3,l2=L2,r2=R2,l3=L1,r3=R1;
    if(check(l1,r1,l2,r2,l3,r3,3,2,1))return 0;
    if(check(l1,r1,l2,r2,r3,l3,3,2,1))return 0;
    if(check(l1,r1,r2,l2,r3,l3,3,2,1))return 0;
    if(check(r1,l1,l2,r2,l3,r3,3,2,1))return 0;
    if(check(r1,l1,r2,l2,l3,r3,3,2,1))return 0;
    if(check(r1,l1,l2,r2,r3,l3,3,2,1))return 0;
    if(check(l1,r1,r2,l2,r3,l3,3,2,1))return 0;
    if(check(r1,l1,r2,l2,r3,l3,3,2,1))return 0;
    cout<<"-1"<<endl;
    return 0;
}