cf(打磨你)(大模拟)

来源:互联网 发布:玛雅注册机mac 编辑:程序博客网 时间:2024/04/29 10:12

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 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
5AAAAABBBBBBBBBBCCCCCCCCCC
input
4 4 2 6 4 2
output
6BBBBBBBBBBBBAAAACCAAAACCAAAACCAAAACC


模拟打印出来三个矩形拼成的正方形,仔细思考一下子也不是没有可能,不过可能就是麻烦了一些。。。。可能有更简洁的办法。

三个矩形拼成正方形无非也只有样例里边给出来的两种大情况,所以我们需要自己的耐心然后努力思考做题就ok啦~~!


#include <iostream>#include <stdio.h>#include <stdlib.h>#include<string.h>#include<algorithm>#include<math.h>#define mod 1000000007using namespace std;typedef long long ll;int main(){    int x[3],y[3];    cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2];    int s=x[0]*y[0]+x[1]*y[1]+x[2]*y[2],t=sqrt((double)s);    if(t*t!=s)        cout<<-1<<endl;    else    {        int b=0;        if(x[0]==t||y[0]==t)b++;        if(x[1]==t||y[1]==t)b++;        if(x[2]==t||y[2]==t)b++;        if(b==3)        {            cout<<t<<endl;            int bl[3];            for(int i=0;i<3;i++)                if(x[i]!=t)                bl[i]=x[i];                else bl[i]=y[i];            for(int j=0;j<bl[0];j++)                {for(int i=0;i<t;i++)                cout<<'A';cout<<endl;                }            for(int j=0;j<bl[1];j++)                {for(int i=0;i<t;i++)                cout<<'B';cout<<endl;                }            for(int j=0;j<bl[2];j++)                {for(int i=0;i<t;i++)                cout<<'C';cout<<endl;                }        }else if(b==1)        {            int bj;            for(int i=0;i<3;i++)                if(x[i]==t||y[i]==t)                bj=i;            if(bj==0)            {                int flag=1,l1,w1;                if(x[0]!=t)l1=x[0];                else l1=y[0];                if(x[1]==x[2]&&y[1]+y[2]==t&&x[1]+l1==t)                {                    w1=y[1];                }else if(x[1]==y[2]&&y[1]+x[2]==t&&x[1]+l1==t)                {                    w1=y[1];                }else if(y[1]==y[2]&&x[1]+x[2]==t&&y[1]+l1==t)                {                    w1=x[1];                }else if(y[1]==x[2]&&x[1]+y[2]==t&&y[1]+l1==t)                {                    w1=x[1];                }else flag=0;                if(!flag)                    cout<<-1<<endl;                else                {                    cout<<t<<endl;                    for(int i=0;i<t;i++)                        if(i<l1)                        {                            for(int j=0;j<t;j++)                                cout<<'A';                            cout<<endl;                        }else                        {                            for(int j=0;j<w1;j++)                                cout<<'B';                            for(int j=w1;j<t;j++)                                cout<<'C';                            cout<<endl;                        }                }            }else if(bj==1)            {                int flag=1,l1,w1;                if(x[1]!=t)l1=x[1];                else l1=y[1];                if(x[0]==x[2]&&y[0]+y[2]==t&&x[0]+l1==t)                {                    w1=y[0];                }else if(x[0]==y[2]&&y[0]+x[2]==t&&x[0]+l1==t)                {                    w1=y[0];                }else if(y[0]==y[2]&&x[0]+x[2]==t&&y[0]+l1==t)                {                    w1=x[0];                }else if(y[0]==x[2]&&x[0]+y[2]==t&&y[0]+l1==t)                {                    w1=x[0];                }else flag=0;                if(!flag)                    cout<<-1<<endl;                else                {                    cout<<t<<endl;                    for(int i=0;i<t;i++)                        if(i<l1)                        {                            for(int j=0;j<t;j++)                                cout<<'B';                            cout<<endl;                        }else                        {                            for(int j=0;j<w1;j++)                                cout<<'A';                            for(int j=w1;j<t;j++)                                cout<<'C';                            cout<<endl;                        }                }            }else            {                int flag=1,l1,w1;                if(x[2]!=t)l1=x[2];                else l1=y[2];                if(x[1]==x[0]&&y[1]+y[0]==t&&x[1]+l1==t)                {                    w1=y[1];                }else if(x[1]==y[0]&&y[1]+x[0]==t&&x[1]+l1==t)                {                    w1=y[1];                }else if(y[1]==y[0]&&x[1]+x[0]==t&&y[1]+l1==t)                {                    w1=x[1];                }else if(y[1]==x[0]&&x[1]+y[0]==t&&y[1]+l1==t)                {                    w1=x[1];                }else flag=0;                if(!flag)                    cout<<-1<<endl;                else                {                    cout<<t<<endl;                    for(int i=0;i<t;i++)                        if(i<l1)                        {                            for(int j=0;j<t;j++)                                cout<<'C';                            cout<<endl;                        }else                        {                            for(int j=0;j<w1;j++)                                cout<<'B';                            for(int j=w1;j<t;j++)                                cout<<'A';                            cout<<endl;                        }                }            }        }        else            cout<<-1<<endl;    }    return 0;}

0 0
原创粉丝点击