您的位置:首页 > 编程语言 > Go语言

codeforces #322 div 2 D. Three Logos (枚举)

2015-10-01 01:41 330 查看
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

题意很清楚.
给三个矩形,问能否拼成一个正方形.
我们先把矩形都躺着放(保证x<=y)
然后容易知道,一共有两种可能的方法
一种是三个矩形罗在一起
另外一种是一个矩形在上面,下面两个矩形竖着放.
后一种方法又因为上面的矩形的不同以及下面两个矩形的横竖放置不同(00 01 10 11)*3
所以一共有12种要枚举...
直接写会累死...
想了个简单点的办法,具体见代码.
一遍AC,好爽!!!


/*************************************************************************
> File Name: code/cf/#322/D.cpp
> Author: 111qqz
> Email: rkz2013@126.com
> Created Time: 2015年09月30日 星期三 17时21分24秒
************************************************************************/
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<stack>
#include<cctype>
#define y1 hust111qqz
#define yn hez111qqz
#define j1 cute111qqz
#define ms(a,x) memset(a,x,sizeof(a))
#define lr dying111qqz
using namespace std;
#define For(i, n) for (int i=0;i<int(n);++i)
typedef long long LL;
typedef double DB;
const int inf = 0x3f3f3f3f;
int ans;
struct Point
{
int x,y;
}p[10];
char maze[110][110];
int ss;
int lst;
int a[10],b[10];
bool solve()
{
if (lst==-1) return false;
//   cout<<"lst:"<<lst<<endl;
if (p[0].x+p[1].x+p[2].x==p[0].y&&p[0].y==p[1].y&&p[0].y==p[2].y)
{
ans = p[0].y;
for ( int i = 0 ; i < p[0].x ; i++)
{
for ( int j = 0 ; j < ans ; j++)
{
maze[i][j] = 'A';
}
}
for ( int i = p[0].x ; i < p[0].x+p[1].x;i++)
{
for ( int j = 0 ; j < ans ; j++)
{
maze[i][j] = 'B';
}
}
for ( int i = p[0].x + p[1].x ; i < ans ; i++)
{
for ( int j = 0 ; j < ans ; j++)
{
maze[i][j] = 'C';
}
}
return true;
}

if (p[a[lst]].x+p[b[lst]].x==p[lst].y&&p[a[lst]].y==p[b[lst]].y&&p[a[lst]].y+p[lst].x==p[lst].y)
{
ans = p[lst].y;
for ( int i = 0 ; i < p[lst].x ; i++)
{
for ( int j =  0  ;  j < ans ; j++)
{
maze[i][j] = char(lst+'A');
}
}
for ( int i = p[lst].x ; i < ans ; i++)
{
for ( int j = 0  ;  j < ans  ;j++)
{
if (j<p[a[lst]].x)
{
maze[i][j]=char(a[lst]+'A');
// cout<<i<<" "<<j<<" "<<char(a[lst]+'A')<<endl;
}
else
{
maze[i][j] = char (b[lst] + 'A');
}
}
}
return true;
}

if (p[a[lst]].x+ p[b[lst]].y==p[lst].y&&p[a[lst]].y==p[b[lst]].x&&p[a[lst]].y+p[lst].x==p[lst].y)
{
//cout<<"22222222222222222"<<endl;
ans = p[lst].y;
for ( int i = 0 ; i < p[lst].x ; i++)
{
for ( int j = 0 ;  j < ans ; j ++)
{
maze[i][j] = char(lst+'A');
}
}

for ( int i = p[lst].x ; i < ans ; i++)
{
for ( int j = 0 ; j < ans ; j++)
{
if (j<p[a[lst]].x)
{
maze[i][j] =char(a[lst]+'A');
}
else
{
maze[i][j] = char(b[lst]+'A');
}
}
}
return true;
}
if (p[a[lst]].y+p[b[lst]].x==p[lst].y&&p[a[lst]].x==p[b[lst]].y&&p[a[lst]].x+p[lst].x==p[lst].y)
{
//cout<<"3333333333333333333333"<<endl;
ans = p[lst].y;
for ( int i = 0 ; i < p[lst].x ; i++)
{
for ( int j =  0  ;  j < ans ; j++)
{
maze[i][j] = char(lst+'A');
}
}
for ( int i = p[lst].x ; i < ans ; i++)
{
for ( int j = 0  ;  j < ans  ;j++)
{
if (j<p[a[lst]].y)
{
maze[i][j]=char(a[lst]+'A');
}
else
{
maze[i][j] = char (b[lst] + 'A');
}
}
}
return true;
}
if (p[a[lst]].y+p[b[lst]].y==p[lst].y&&p[a[lst]].x==p[b[lst]].x&&p[a[lst]].x+p[lst].x==p[lst].y)
{
//    cout<<"44444444444444444444444444"<<endl;
ans = p[lst].y;
for ( int i = 0 ; i < p[lst].x ; i++)
{
for ( int j =  0  ;  j < ans ; j++)
{
maze[i][j] = char(lst+'A');
}
}
for ( int i = p[lst].x ; i < ans ; i++)
{
for ( int j = 0  ;  j < ans  ;j++)
{
if (j<p[a[lst]].y)
{
maze[i][j]=char(a[lst]+'A');
//   cout<<"haaa"<<a[lst]+'A'<<endl;
}
else
{
maze[i][j] = char (b[lst] + 'A');
}
}
}
return true;
}
return false;
}
int main()
{
#ifndef  ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif

ss = 0;
lst = -1;
a[0]=1;b[0]=2;
a[1]=0;b[1]=2;
a[2]=0;b[2]=1;
for ( int i = 0 ; i < 3 ; i++)
{
scanf("%d %d",&p[i].x,&p[i].y);
if (p[i].x>p[i].y) swap(p[i].x,p[i].y);
ss += p[i].x*p[i].y;
}
for ( int i = 0 ; i < 3 ; i++)
{
if (p[i].y*p[i].y==ss)
{
lst = i;
}
}
if (solve())
{
printf("%d\n",ans);
for ( int i = 0 ; i < ans ; i++)
{
for ( int j = 0 ; j < ans ;  j++)
{
printf("%c",maze[i][j]);
}
printf("\n");
}
}
else
{
puts("-1");
}
#ifndef ONLINE_JUDGE

fclose(stdin);
#endif
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: