您的位置:首页 > 编程语言 > Go语言

Three Logos(模拟)

2015-09-29 13:45 567 查看
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
5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC


input
4 4 2 6 4 2


output
6
BBBBBB
BBBBBB
AAAACC
AAAACC
AAAACC
AAAACC

这题理解起来不难,就是实现起来太过于复杂了,这题Wa了5-6次才A出来。其实这题只要将每一种情况分开出来讨论就行了。还有就是三个矩形中只要找到那个边最大的一个出来,只讨论剩下的矩形就行了。
AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
typedef __int64 ll;
#define T 100005
int flag,x,y;
struct node
{
int L,R;
int i;
bool operator<(node& a)const{
return L>a.L;
}
}a[3];
int main(){
/* freopen("input.txt","r",stdin);*/
int i;
while(~scanf("%d%d%d%d%d%d",&a[0].L,&a[0].R,&a[1].L,&a[1].R,&a[2].L,&a[2].R))
{
node ln,rn;flag=0;
for(i=0;i<3;++i){
a[i].i = i;
if(a[i].L<a[i].R)swap(a[i].L,a[i].R);
}
sort(a,a+3);
x = a[0].L,y=x-a[0].R;
ln = a[1],rn = a[2];
if(ln.L==rn.L&&rn.L==x&&ln.R+rn.R==y){
//当剩下的两个矩形的最大边也和第一条边相等,则直接输出行数
flag=1;
printf("%d\n",x);
for(i=0;i<3;++i){
for(int j=0;j<a[i].R;++j){
for(int k=0;k<x;++k){
printf("%c",'A'+a[i].i);
}printf("\n");
}
}
}
else
{
int col=x,row=y,t;
//矩形以(1)(2)(3)命名
if(ln.L==rn.L&&ln.L==y&&ln.R+rn.R==x){
//当(2)(3)最小边相加等于(1)最大边时且(2)(3)最大边等于(1)的最大边-(1)最小边
t = ln.R;
flag=1;
}
if(ln.R==rn.R&&ln.R==y&&ln.L+rn.L==x){
//当(2)(3)最大边相加等于(1)最大边时且(2)(3)最小边等于(1)的最大边-(1)最小边
flag=1;
t=ln.L;
}
if(ln.L==rn.R&&ln.R+rn.L==x){
//当(2)最大边=(3)最小边且(2)最小边+(3)的最大边=(1)最大边
t=ln.R;
flag=1;
}
if(ln.R==rn.L&&ln.L+rn.R==x){
//当(2)最小边=(3)最大边且(2)最大边+(3)的最小边=(1)最大边
t = ln.L;
flag=1;
}
if(flag){
printf("%d\n",x);
for(i=0;i<a[0].R;++i){
for(int j=0;j<a[0].L;++j)
printf("%c",'A'+a[0].i);
printf("\n");
}
for(i=0;i<row;++i){
for(int j=0;j<col;++j)
if(j<t)
printf("%c",'A'+a[1].i);
else
printf("%c",'A'+a[2].i);
printf("\n");
}
}
else
printf("-1\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces