Three Logos(模拟)

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值