codeforces581D
Three Logos
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
5 1 2 5 5 2
5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC
4 4 2 6 4 2
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的更多相关文章
随机推荐
- 3.1依赖注入「深入浅出ASP.NET Core系列」
希望给你3-5分钟的碎片化学习,可能是坐地铁.等公交,积少成多,水滴石穿,谢谢关注. 从UML来理解依赖 1.1什么是依赖 我们先看下图 可以简单理解,一个HomeController类使用到了DBC ...
- java 并发多线程显式锁概念简介 什么是显式锁 多线程下篇(一)
目前对于同步,仅仅介绍了一个关键字synchronized,可以用于保证线程同步的原子性.可见性.有序性 对于synchronized关键字,对于静态方法默认是以该类的class对象作为锁,对于实例方 ...
- asp.net 仿微信端菜单设置
第一步:添加引用文件 <link rel="stylesheet" href="~/assets/css/bootstrap.min.css"> & ...
- Web前端 web的学习之路2
2019 年 Web 开发技术指南和趋势 2019/01/23 · JavaScript · 趋势 转载:原文出处: 李棠辉(http://web.jobbole.com/95622/) 以下内 ...
- Android View的重绘过程之Measure
博客首页:http://www.cnblogs.com/kezhuang/p/ View绘制的三部曲, 测量,布局,绘画今天我们分析测量过程 view的测量是从ViewRootImpl发起的,Vie ...
- 基于jwt的用户登录认证
最近在app的开发过程中,做了一个基于token的用户登录认证,使用vue+node+mongoDB进行的开发,前来总结一下. token认证流程: 1:用户输入用户名和密码,进行登录操作,发送登录信 ...
- python使用rabbitMQ介绍三(发布订阅模式)
一.模式介绍 在前面的例子中,消息直接发送到queue中. 现在介绍的模式,消息发送到exchange中,消费者把队列绑定到exchange上. 发布-订阅模式是把消息广播到每个消费者,每个消费者接收 ...
- Django-2- 模板路径查找,模板变量,模板过滤器,静态文件引用
模板路径查找 路径配置 2. templates模板查找有两种方式 2.1 - 在APP目录下创建templates文件夹,在文件夹下创建模板 2.2 - 在项目根目录下创建templates文件夹, ...
- c/c++ 继承与多态 文本查询的小例子(智能指针版本)
为了更好的理解继承和多态,做一个文本查询的小例子. 接口类:Query有2个方法. eval:查询,返回查询结果类QueryResult rep:得到要查询的文本 客户端程序的使用方法: //查询包含 ...
- js坚持不懈之14:不要在文档加载之后使用 document.write()示例
在看w3school的JavaScript教程时,关于文档输出流中有这么一句话:绝不要在文档加载之后使用 document.write().这会覆盖该文档. 不太明白什么意思,找了一个例子: < ...