Three Logos

CodeForces - 581D

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 nuppercase 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.

Examples

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 sol:只有三个标记当然可以暴力模拟,就是判-1略微蛋疼
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n=,n1,n2,n3,m1,m2,m3;
char Map[N][N];
inline void OutPut()
{
Wl(n);
int i,j;
for(i=;i<=n;i++)
{
for(j=;j<=n;j++) putchar(Map[i][j]);
putchar('\n');
}
}
#define NO {puts("-1"); exit(0);}
inline void Judge()
{
if(n*n!=(n1*m1+n2*m2+n3*m3)) NO
if(n1==n&&n2==n&&n3==n) if(m1+m2+m3!=n) NO
int i,j,c1=,c2=,c3=;
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(Map[i][j]=='A') c1++;
else if(Map[i][j]=='B') c2++;
else if(Map[i][j]=='C') c3++;
}
}
if((c1!=n1*m1)||(c2!=n2*m2)||(c3!=n3*m3)) NO
}
int main()
{
int i,j,Lastn,Lastm;
R(n1); R(m1); R(n2); R(m2); R(n3); R(m3);
if(n1<m1) swap(n1,m1); if(n2<m2) swap(n2,m2); if(n3<m3) swap(n3,m3);
n=max(n1,max(m1,max(n2,max(m2,max(n3,m3)))));
memset(Map,' ',sizeof Map);
if(n1==n)
{
for(i=;i<=n1;i++) for(j=;j<=m1;j++) Map[i][j]='A';
if(n2==n)
{
for(i=;i<=n;i++) for(j=m1+;j<=m1+m2;j++) Map[i][j]='B';
}
else
{
if(n2+m1==n) swap(n2,m2);
for(i=;i<=n2;i++) for(j=m1+;j<=n;j++) Map[i][j]='B';
}
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(!isupper(Map[i][j])) Map[i][j]='C';
}
}
}
else if(n2==n)
{
for(i=;i<=n2;i++) for(j=;j<=m2;j++) Map[i][j]='B';
if(n1==n)
{
for(i=;i<=n;i++) for(j=m2+;j<=m2+m1;j++) Map[i][j]='A';
}
else
{
if(n1+m2==n) swap(n1,m1);
for(i=;i<=n1;i++) for(j=m2+;j<=n;j++) Map[i][j]='A';
}
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(!isupper(Map[i][j])) Map[i][j]='C';
}
}
}
else
{
for(i=;i<=n3;i++) for(j=;j<=m3;j++) Map[i][j]='C';
if(n1==n)
{
for(i=;i<=n;i++) for(j=m3+;j<=m3+m1;j++) Map[i][j]='A';
}
else
{
if(n1+m3==n) swap(n1,m1);
for(i=;i<=n1;i++) for(j=m3+;j<=n;j++) Map[i][j]='A';
}
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(!isupper(Map[i][j])) Map[i][j]='B';
}
}
}
Judge();
OutPut();
return ;
}
/*
Input
5 1 5 2 5 2
Output
5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC Input
4 4 2 6 4 2
Output
6
BBBBBB
BBBBBB
AAAACC
AAAACC
AAAACC
AAAACC input
100 100 100 100 100 100
output
-1
*/
 

codeforces581D的更多相关文章

随机推荐

  1. .NET开发中基础问题,CODE First AND DB First(大牛自动忽略,小白可以看一下)

    最近在做一个新项目开发时,碰到了下面这个问题.在使用EF时,提示错误信息 To continue using Database First or Model First ensure that the ...

  2. SmartUpload工具包的中文乱码问题详解

    关于SmartUpload工具包的中文乱码问题,输出在服务端的中文显示是乱码,而英文数字,没有任何问题,我在网上看了其他人的问题和回答,让我觉得有道理,却又用不着,最后在多次试验中,终于找到了问题所在 ...

  3. JavaScript学习一之数据校验

    JavaScript页面进行数据校验 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  4. RFID NFC

    RFID 和 NFC 的区别: ()NFC与RFID在物理层面看上去很相似,但实际上是两个完全不同的领域,因为RFID本质上属于识别技术,而NFC属于通信技术. ()NFC将非接触读卡器.非接触卡和点 ...

  5. Sharepoint 2013搜索服务配置总结(实战)

    分享人:广州华软 星尘 一. 前言 SharePoint 2013集成了Fast搜索,相对于以前版本搜索的配置有了一些改变,在安装部署Sharepoint 2013时可以选择默认创建搜索服务,但有时候 ...

  6. 如何让nextcloud支持avi文件在线播放

    默认的nextcloud是不支持avi文件播放的,google查了一圈,都说是没法支持. 然而我觉得都是html5写的,为啥偏偏不支持. 查了一些资料,发现还是官方的代码少写了东西,可能是没考虑那么全 ...

  7. hadoop集群的搭建

    hadoop集群的搭建 1.ubuntu 14.04更换成阿里云源 刚刚开始我选择了nat模式,所有可以连通网络,但是不能ping通,我就是想安装一下mysql,因为安装手动安装mysql太麻烦了,然 ...

  8. 【升鲜宝】生鲜配送管理系统_升鲜宝供应链系统V2.0 客户管理模块功能与设计,欢迎大家批评指点。

    [升鲜宝] 客户管理模块功能设计与介绍 客户模块分为以下子功能  客户列表 价格组 价格组商品价格 客户退货 客户星级 客户类型 客户存储位 客户来源 物流公司 打印模板 子模块介绍        客 ...

  9. Android launcher 壁纸 wallpaper

    壁纸分为动态和静态两种: 如果只需要修改默认静态壁纸,替换frameworks/base/core/res/res/drawable/default_wallpaper.jpg即可,或者在源码中修改对 ...

  10. (办公)springboot配置全局异常

    项目用到了springboot,本来很高兴,但是项目里什么东西都没有,验证,全局异常这些都需要自己区配置.最近springboot用的还是蛮多的,我还是做事情,把经验发表一下.全局统一的异常,首先异常 ...