码迷,mamicode.com
首页 > 其他好文 > 详细

cf581D Three Logos

时间:2015-09-28 23:53:27      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:

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
5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC
input
4 4 2 6 4 2
output
6
BBBBBB
BBBBBB
AAAACC
AAAACC
AAAACC
AAAACC

 题意是给定三个矩形的长宽,问是否能放在同一个正方形中。

因为是三个矩形填一个正方形,一定有一个矩形的长度为正方形的边长,同时这也是矩形的最大长度(这个yy一下很容易想到)

然后就是模拟了

有两种情况,要么是三个排三行(比如样例一),要么是一横两竖(比如样例二)

要注意排一横两竖的时候ABC分别对应第一二三个矩形,这个顺序不能互换(其实也就是复制粘贴3次啦)

因为细节跪了好几次。。我真是越来越弱了。。

技术分享
 1 #include<bitset>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<iostream>
 6 #include<algorithm>
 7 #define LL long long
 8 #define inf 0x7fffffff
 9 #define pa pair<int,int>
10 #define pi 3.1415926535897932384626433832795028841971
11 using namespace std;
12 inline LL read()
13 {
14     LL x=0,f=1;char ch=getchar();
15     while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
16     while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
17     return x*f;
18 }
19 int x1,y1,x2,y2,x3,y3;
20 int main()
21 {
22     x1=read();y1=read();x2=read();y2=read();x3=read();y3=read();
23     if (x1<y1)swap(x1,y1);
24     if (x2<y2)swap(x2,y2);
25     if (x3<y3)swap(x3,y3);
26     int l=max(max(x1,x2),x3);
27     if (x1*y1+x2*y2+x3*y3!=l*l){printf("-1");return 0;}
28     if (l==x1&&l==x2&&l==x3)
29     {
30         printf("%d\n",l);
31         for (int i=1;i<=y1;i++)
32             {for (int j=1;j<=x1;j++)printf("A");printf("\n");}
33         for (int i=1;i<=y2;i++)
34             {for (int j=1;j<=x2;j++)printf("B");printf("\n");}
35         for (int i=1;i<=y3;i++)
36             {for (int j=1;j<=x3;j++)printf("C");printf("\n");}
37     }else
38     {
39         if (x1==l)
40         {
41             if (x2==l-y1)swap(x2,y2);if (x3==l-y1)swap(x3,y3);
42             if (!(x2+x3==l&&y2+y1==l&&y2==y3)){printf("-1");return 0;}
43             printf("%d\n",l);
44             for (int i=1;i<=y1;i++)
45                 {for (int j=1;j<=x1;j++)printf("A");printf("\n");}
46             for (int i=1;i<=l-y1;i++)
47                 {
48                     for (int j=1;j<=x2;j++)printf("B");
49                     for (int j=1;j<=x3;j++)printf("C");
50                     printf("\n");
51                 }
52         }
53         if (x2==l)
54         {
55             if (x1==l-y2)swap(x1,y1);if (x3==l-y2)swap(x3,y3);
56             if (!(x1+x3==l&&y1+y2==l&&y1==y3)){printf("-1");return 0;}
57             printf("%d\n",l);
58             for (int i=1;i<=y2;i++)
59                 {for (int j=1;j<=x2;j++)printf("B");printf("\n");}
60             for (int i=1;i<=l-y2;i++)
61                 {
62                     for (int j=1;j<=x1;j++)printf("A");
63                     for (int j=1;j<=x3;j++)printf("C");
64                     printf("\n");
65                 }
66         }
67         if (x3==l)
68         {
69             if (x1==l-y3)swap(x1,y1);if (x2==l-y3)swap(x2,y2);
70             if (!(x1+x2==l&&y1+y3==l&&y1==y2)){printf("-1");return 0;}
71             printf("%d\n",l);
72             for (int i=1;i<=y3;i++)
73                 {for (int j=1;j<=x3;j++)printf("C");printf("\n");}
74             for (int i=1;i<=l-y3;i++)
75                 {
76                     for (int j=1;j<=x1;j++)printf("A");
77                     for (int j=1;j<=x2;j++)printf("B");
78                     printf("\n");
79                 }
80         }
81     }
82 }
cf581D

 

cf581D Three Logos

标签:

原文地址:http://www.cnblogs.com/zhber/p/4845169.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!