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. SQL 注入~MySQL专题

    Recently, 团队在做一个关于SQL的项目,这个专题是项目中的一部分,该部分正是由我来负责的.今天,分享给正在奋斗中的伙伴们,愿,你们在以后的学习道路中能有自己的收获.              ...

  2. Android HandlerThread使用介绍以及源码解析

    摘要: 版权声明:本文出自汪磊的博客,转载请务必注明出处. 一.HandlerThread的介绍及使用举例              HandlerThread是什么鬼?其本质就是一个线程,但是Han ...

  3. kubernetes系列10—存储卷详解

    本文收录在容器技术学习系列文章总目录 1.认识存储卷 1.1 背景 默认情况下容器中的磁盘文件是非持久化的,容器中的磁盘的生命周期是短暂的,这就带来了一系列的问题:第一,当一个容器损坏之后,kubel ...

  4. SQLServer事务在C#当中的应用

    1:事务是什么 事务指的是一系列SQL操作的逻辑工作单元,,要么完全地执行,要么完全地不执行. 一个逻辑工作单元必须有4个属性,原子性(Atomic).一致性(Consistent).隔离型(Isol ...

  5. 2017-2018年Scrum状态调查报告

    HOW SCRUM IS USED 在2017年的报告中,Scrum的应用范围在扩大,已经从其发源的IT部门扩展到了相距甚远的业务部门.2017-2018年度报告的其中一个主要目标就是关注更广泛的敏捷 ...

  6. c#中缓存的使用

    缓存的使用: 缓存是分布式系统中的重要组件,主要解决高并发,大数据场景下,热点数据访问的性能问题.提供高性能的数据快速访问,提高数据的读取速度.因为服务器和应用客户端之间存在着流量的瓶颈,所以读取大容 ...

  7. EF 外键不显示、如何让外键显示!增、删、改 操作时,外键不显示,只显示导航属性!

    一.问题描述:EF 外键不显示.如何让外键显示!增.删.改 操作时,外键不显示,只显示导航属性! EF 添加.增加.插入数据时,外键不显示! 二.解决方案:在根据数据库生成模型的时候,选中“在模型中” ...

  8. SAP HUM 事务代码HUMO为整托做Scrap

    SAP HUM 事务代码HUMO为整托做Scrap HUMO事务代码查询结果里,选择某个HU, 回车,过账成功, 2019-04-10 写于苏州市.  

  9. appium+python搭建自动化测试框架_Appium元素定位(二)

    Appium元素定位: 工具:Android\android-sdk\tools    uiautomatorviewer.bat 1. id定位: self.driver.find_element_ ...

  10. jQuery字母大小写转换函数

    toLowerCase() ------ 将字符串中的所有字符都转换成小写: toUpperCase() ------ 将字符串中的所有字符都转换成大写: