Codeforces 432E Square Tiling (constructed) __ Greed

Source: Internet
Author: User

E. Square tiling time limit per test 1 second memory limit/test 256 megabytes input standard input output standard out Put

You have a NXM rectangle table, its cells are is not initially painted. Your task is to paint all cells of the table. The resulting picture should is a tiling of the table with squares. More Formally:each cell must is painted some color (the colors are marked by uppercase Latin); We'll 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 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) are considered lexicographically less than the other one (let's call it Y), If:consider all The table cells from-to-right and to bottom (the "the" the "the" N, the "the", and so on); Let's find in this order the "the" the "the" the has distinct colors in two colorings; The letter so marks the color of the cell in X, goes alphabetically before the "letter" that marks the color of the cell I n Y. Examples input

1 3
Output
ABA
Input
2 2
Output
AA
AA
Input
3 4
Output
Aaab
AAAC
Aaab


Title: Fill the matrix with 26 uppercase letters, requiring the same letter to be together to form a square, requiring the smallest dictionary order of the Matrix (from left to right, top to bottom)

The work: from the top down from the trip, can be small.
(I,J) be able to dye the color k when and only if (I-1,J) and (i,j+1) do not dye the color K, and the first line of the color k is the top line, then the square to expand a circle

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define N-
using namespace std;
int n,m;
int a[n][n];
int main ()
{
	scanf ("%d%d", &n,&m);
	for (int i=1;i<=n;i++)
	 (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");
	}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.