您的位置:首页 > 其它

codeforces 432E Square Tiling(构造)

2016-05-27 19:12 323 查看
E. Square Tiling

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

You have an n × m rectangle table, its cells are not initially painted. Your task is to paint all cells of the table. The
resulting picture should be a tiling of the table with squares. More formally:

each cell must be painted some color (the colors are marked by uppercase Latin letters);

we will assume that two cells of the table are connected if they are of the same color and share a side; each connected region of the table must form a square.

Given n and m,
find lexicographically minimum coloring of the table that meets the described properties.

Input

The first line contains two integers, n and m (1 ≤ n, m ≤ 100).

Output

Print lexicographically minimum coloring of the table that meets the described conditions.

One coloring (let's call it X) is considered lexicographically less than the other one (let's call it Y), if:

consider all the table cells from left to right and from top to bottom (first, the first cell in the first row, then the second cell in the first row and so on);

let's find in this order the first cell that has distinct colors in two colorings;

the letter that marks the color of the cell in X, goes alphabetically before the letter that marks the color of the cell in Y.

Examples

input
1 3


output
ABA


input
2 2


output
AA
AA


input
3 4


output
AAAB
AAAC
AAAB


题目大意:用26个大写字母将矩阵填满,要求挨在一起的相同字母必须构成一个正方形,要求构成的矩阵的字典序最小(从左往右,从上到下)

题解:从上往下从前往后,能小就小。

(i,j)能够染颜色k当且仅当(i-1,j)与(i,j+1)没有染颜色k,且第i行前面的颜色k都是第一行,那么就将正方形都扩大一圈

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 103
using namespace std;
int n,m;
int a

;
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
if (a[i][j]) continue;
for (int k=1;k<=26;k++)
{
if (a[i-1][j]==k||a[i][j+1]==k) continue;
if (a[i][j-1]==k||j==1){
int num=0; int l=i;
while (l<=n&&a[l][j-1]==k) num++,l++;
num++;
if (i+num-1>n) continue;
for (int t=i;t<=i+num-1;t++) a[t][j]=k;
for (int t=j;t>=j-num+1;t--) a[i+num-1][t]=k;
}
a[i][j]=k;
break;
}
}
//for (int i=1;i<=m;i++)
//cout<<a[1][i]<<" ";
//cout<<endl;
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
printf("%c",a[i][j]+64);
printf("\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: