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. C#语法——委托,架构的血液

    本篇文章主要介绍委托的应用. 委托是大家最常见的语法了,但会用与精通之间的差别是巨大的. 一个程序员如果不能精通委托,那么,他永远无法成为高级程序员. 所以,让我们把委托刻到血液里吧. 这样,你才能称 ...

  2. 博主新建Linux学习交流群,欢迎广大大神入驻~

    一转眼2018已经过去,博主在博客园辛勤耕耘了1年多,也结识了很多志同道合的道友: 收获了“基”情满满的友谊的同时,也大大拓宽了自己的眼界~ 深深感到在漫漫的学习之路,需要有道友一同共勉和相互激励! ...

  3. .NET CAD二次开发学习 直线画矩形并转换成组

    主要代码: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System ...

  4. 引用KBC.PetroSIM.Interop的dll,在代码中调用时出现 80040154 没有注册类 的错误

    失败的尝试: regsvr32注册:模块已加载,但找不到入口点DllRegisterServer regasm注册:需写上regasm的完整路径,注册成功,但问题依旧 将项目的平台改为x86:问题依旧 ...

  5. NLog组件

    接触.net项目的同志们都清楚,最初在项目中记录日志常用的是log4net日志组件,随着.net框架的不对优化升级,最近新流行的日志框架nlog,下面我就对nlog组件说说自己的认知: 下载 通过Nu ...

  6. Odoo:全球第一免费开源ERP库龄表的简单实现方法(无需二开)

    问题背景 希望查看库龄超过30天的货物,该如何实现?此种简单数据查询需要二开吗? 解决方案 方法一:Stock Quant列表视图增加过滤器 <filter string="库龄超30 ...

  7. C++一种高精度计时器

    在windows下可以通过QueryPerformanceFrequency()和QueryPerformanceCounter()等系列函数来实现计时器的功能. 根据其函数说明,其精度能够达到微秒级 ...

  8. Python 标准类库- 因特网协议于支持之UUID

    标准类库- 因特网协议于支持之UUID by:授客 QQ:1033553122   测试环境 python3 UUID生成函数定义 uuid.getnode() 获取一个表示硬件地址的48位正整数.第 ...

  9. 在Windows Phone 8.1中使用Sqlite数据库

    前言 我的工作目前不涉及到Windows phone的开发,但是业余时间也开发过几款app.以前由于各种条件的限制,只接触到WP8.0设备的app开发. 最近几个月开始将WP8的应用迁移到WP8.1, ...

  10. JAVA 四舍五入Math.round方法

    今天由于测试场景,利息的计算中涉及小数点的保留.保留的规则是:两位小数+四舍五入方式 使用的语言是JAVA, 看了许多网上的方法.因为最后保留的小数还会进行计算.所以我考虑最好不要保留的结果是Stri ...