Codeforces Round #322 D.Three Logos

来源:互联网 发布:如何找淘宝小二 编辑:程序博客网 时间:2024/05/22 10:49
D. Three Logos
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Three companies decided to order a billboard with pictures of their logos. A billboard is a bigsquare 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 andyi determine the length and width of the logo of thei-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 squaren, where you can place all the three logos. Each of the nextn 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
5AAAAABBBBBBBBBBCCCCCCCCCC
Input
4 4 2 6 4 2
Output
6BBBBBBBBBBBBAAAACCAAAACCAAAACCAAAACC本题题目意思也较为清楚,就是叫你给你三个长方形的长和宽,叫你判断他们能否组成一个正方形,并输出形状
#include<bits/stdc++.h>using namespace std;int main(){    int x1,y1,x2,y2,x3,y3;    while(scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){        int area=x1*y1+x2*y2+x3*y3;        int k=sqrt(area);        if(k*k==area){            if(y1==k)                swap(x1,y1);            if(y2==k)                swap(x2,y2);            if(y3==k)                swap(x3,y3);            if(x1==k&&x2==k&&x3==k){                printf("%d\n",k);                for(int i=1;i<=y1;i++){                    for(int j=1;j<=x1;j++)                        printf("A");                    printf("\n");                }                for(int i=1;i<=y2;i++){                    for(int j=1;j<=x2;j++)                        printf("B");                    printf("\n");                }                for(int i=1;i<=y3;i++){                    for(int j=1;j<=x3;j++)                        printf("C");                    printf("\n");                }                continue;            }            int sd=0;            if(x2==k){                sd=1;                swap(x1,x2);                swap(y1,y2);            }            if(x3==k){                sd=2;                swap(x1,x3);                swap(y1,y3);            }            if(y2==k-y1){                swap(x2,y2);            }            if(y3==k-y1){                swap(x3,y3);            }            if(x2==k-y1&&x3==k-y1&&y2+y3==k){                printf("%d\n",k);                for(int i=1;i<=y1;i++){                    for(int j=1;j<=x1;j++)                        printf("%c",'A'+sd);                    printf("\n");                }                if(sd==0){                    for(int i=1;i<=x2;i++){                        for(int j=1;j<=y2;j++)                            printf("%c",'B');                        for(int j=1;j<=y3;j++)                            printf("%c",'C');                        printf("\n");                    }                }                if(sd==1){                    for(int i=1;i<=x2;i++){                        for(int j=1;j<=y2;j++)                            printf("%c",'A');                        for(int j=1;j<=y3;j++)                            printf("%c",'C');                        printf("\n");                    }                }                if(sd==2){                    for(int i=1;i<=x2;i++){                        for(int j=1;j<=y2;j++)                            printf("%c",'B');                        for(int j=1;j<=y3;j++)                            printf("%c",'A');                        printf("\n");                    }                }                continue;            }            else{                printf("-1\n");            }        }        else{            printf("-1\n");        }    }    return 0;}


0 0
原创粉丝点击