uva - 10230 - Savage Garden

本文介绍了Mr. Savage想要改善他的著名花园Savage Garden的布局,计划将其分成小正方形区域,每个区域边长为2的幂,并组合成L形区域来种植不同种类的植物。为此,他雇佣了一位规划师来生成花园的规划方案。输入包括花园的大小和Mr. Savage的房子位置,输出是一个矩阵,显示了花园的布局,其中'*'代表房子,'a'-'z'代表不同的L形区域。规划师需要确保相邻的L形区域使用不同的字符表示,并且至少存在一种解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1171


 

Problem B: Savage Garden

Mr. Savage has a huge square-shaped garden named Savage Garden. The Savage Garden is very famous for its rare plants and amazing beauty. Currently, he is thinking of improving the garden by changing the orientation of plants into a special way. He wishes to divide the garden into smaller square regions such that the length of the complete square region is a power of two. Then, he wants to group the regions into L-shaped regions formed by three smaller squares. Each L-shaped region will have a different plant from the adjacent L-shaped regions. He feels that the L will represent Love and his loved ones from all over the world and in the heavens can enjoy its beauty forever.

You have been hired by Mr. Savage to generate a plan for Savage Garden. 

Input

Input consists of several test cases. Each test case specifies three integers, NX and YN1� N� 10 represents that Savage Garden is of size 2N X 2N, after division. X and Y indicate the region where his house is located. For example, topmost-leftmost region is indicated by X=1 and Y=1. Of course, he doesn't want his house to be planted with saplings. So, make sure you leave his house intact while deriving the plan. You can assume that the co-ordinates given are always within the square region.

Output

For each test case, output a square matrix showing the Savage Garden. Indicate his house by the character '*'. All other regions should be indicated by alphabets 'a'-'z'. Character used to represent one L-shaped region should be different from the ones used to represent its neighboring L-shaped regions. Assume that each small square region has 8 neighbors. If there are many solutions, you may output any of them. You may assume that there is at least one solution for the given test cases. Output a blank line after each test case.

Sample Input

2 3 4

Sample Output

aadd
abbd
cbee
cc*e


解题思路:
题目中的L-shape 只有三个小格子。
首先,将矩阵以2*2为单位分为小方格,每个方格里面填同种颜色,注意题目里面是相邻的8个格子不同色,因此这道题至少需要5种颜色。被坑了无数次,以为3色就搞定,就因为8个格子不同色。
然后,对于原矩阵,对等分为四大块(S,S)(S,L)(L,S)(L,L),判断目标在哪个块中,
1.对于目标所在块,递归
2.对剩余的3块,从每一块中掏出一个小方格,构成L-shape,然后假定目标在某一个角落,递归



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值