Codeforces 581D Three Logos

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


非常好玩的图形模拟判断题,由于保证了是正方形,一开始就可以排除掉很多数据,然后边长也是固定的,接下去就把所有3种矩形所有可能的排布都试一遍,矩形首先自身可以换方向,故友2^3次,矩形排布互相可以换位置,故友3*2=6种,矩形排的样式共有4种分别为:

111   1           11     1

         11         1       1

                               1

根据这些样式把对应的长宽数据对应进去,因为一开始限制了面积因素和边长,如果一个样式能够在竖边长和横边长都符合正确边长,就一定是正确的答案。具体细节请参考我的代码自己斟酌。


代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<algorithm>
#include<fstream>
#include<queue>
#include<stack> 
#include<vector>
#include<cmath>
#include<iomanip>
#define rep(i,n) for(i=1;i<=n;i++)
#define MM(a,t) memset(a,t,sizeof(a))
#define INF 1e9
typedef long long ll;
#define mod 1000000007
using namespace std;
class rec{
  public:
   int l,w;	
}a[100];
int n,xx;
int f[300][5][5];
int res[500][500];
class point{
  public:
    int x,y;
}se[10][5];
void fun(int nn,int ii,int jj,int kk){
  n++;
  f[n][se[nn][1].x][se[nn][1].y]=ii;
  f[n][se[nn][2].x][se[nn][2].y]=jj;
  f[n][se[nn][3].x][se[nn][3].y]=kk;	
}
void setup(){
  int i,j,k,nn;
  
  n=0;
  se[1][1].x=1; se[1][1].y=1; se[1][2].x=2; se[1][2].y=1; se[1][3].x=3; se[1][3].y=1;
  se[2][1].x=1; se[2][1].y=1; se[2][2].x=2; se[2][2].y=1; se[2][3].x=2; se[2][3].y=2;
  se[3][1].x=1; se[3][1].y=1; se[3][2].x=1; se[3][2].y=2; se[3][3].x=2; se[3][3].y=1;
  se[4][1].x=1; se[4][1].y=1; se[4][2].x=1; se[4][2].y=2; se[4][3].x=1; se[4][3].y=3;
  
  rep(nn,4)
  for(i=1;i<=4;i+=3)
    for(j=2;j<=5;j+=3)
	  for(k=3;k<=6;k+=3){
        fun(nn,i,j,k);	
        fun(nn,i,k,j);
        fun(nn,j,i,k);
        fun(nn,j,k,i);
        fun(nn,k,i,j);
        fun(nn,k,j,i);
  	  }	
}
bool cal(int ii){
  int l=0,w=0;
  int i,j;
  	
  rep(i,3){
  	if(a[f[ii][i][1]].l==0) continue;
  	w=0;
    rep(j,3){
      w+=a[f[ii][i][j]].w; 	
    }
    l+=a[f[ii][i][1]].l;
    if(w!=xx) return false;
  }
  if(l!=xx) return false;
  return true;
}
void pp(int x,int y,int ii){
  int i,j;
  
  for(i=x+1;i<=x+a[ii].l;i++)
    for(j=y+1;j<=y+a[ii].w;j++)
	  res[i][j]=ii;	
}
void prt(int ii){
  int i,j;
  int l=0,w;
  
  rep(i,3){
  	w=0;
    rep(j,3){  	
	  if(f[ii][i][j]==0) break;
   	  pp(l,w,f[ii][i][j]);
      w+=a[f[ii][i][j]].w; 	
    }
    l+=a[f[ii][i][1]].l;
  }	
  printf("%d\n",xx);
  rep(i,xx){
    rep(j,xx){
   	  if(res[i][j]==1 || res[i][j]==4) printf("A");
   	  else if(res[i][j]==2 || res[i][j]==5) printf("B");
   	       else                             printf("C");
    }
    printf("\n");
  }

}
int main(){
	int i,j;
	int sum;
	bool ff;
	
	setup();
	while(1){
	  sum=0; MM(res,0); MM(a,0);
	  rep(i,3){
  	    scanf("%d%d",&a[i].l,&a[i].w);
		a[i+3].l=a[i].w; a[i+3].w=a[i].l;	
		sum+=a[i].l*a[i].w;
  	  }	
  	  xx=sqrt(sum+0.1);
  	  if(xx*xx!=sum){
  	    printf("-1\n");
		break;	
  	  }ff=false;
  	  rep(i,n) 	  
  	  if(cal(i)){
  	    prt(i);
  	    ff=true;
		break;	
  	  }
  	  if(!ff) printf("-1\n");
  	  break;
	}
	
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值