【贪心】【uva11520】 Fill the Square
填充正方形(Fill the Square, UVa 11520)
在一个n×n网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同。如果有多种填法,则要求按照从上到下、从左到右的顺序把所有格子连接起来得到的字符串的字典序应该尽量小。
【输入格式】
输入的第一行为测试数据组数T。每组数据的第一行为整数n(n≤10),即网格的行数和列数;以下n行每行n个字符,表示整个网格。为了清晰起见,本题用小数点表示没有填字母的格子。
【输出格式】
对于每组数据,输出填满字母后的网格。
【样例输入】
2
3
...
...
...
3
...
A..
...
【样例输出】
Case 1:
ABA
BAB
ABA
Case 2:
BAB
ABA
BAB
水题一枚
上代码
#include<cstdio>
#include<cstring>
const int maxn=12;
char map[maxn][maxn];
int n;
int input()
{
char c;
memset(map,0,sizeof(map));
scanf("%d\n",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
scanf("%c",&map[i][j]);
scanf("%c",&c);
}
return 0;
}
int getans()
{
for(int j=1;j<=n;j++)
for(int i=1;i<=n;i++)
for(char k='A';k<='Z';k++)
{
if(map[i][j]=='.')
if(map[i-1][j]!=k&&map[i][j-1]!=k&&map[i][j+1]!=k&&map[i+1][j]!=k)
{ map[i][j]=k;break;}
else;
else break;
}
return 0;
}
int putans(int Case)
{
printf("Case %d:\n",Case);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
printf("%c",map[i][j]);
printf("\n");
}
}
int main()
{
int T,TT;
scanf("%d",&T);
TT=T;
while(T--)
{
input();
getans();
putans(TT-T);
}
return 0;
}
【贪心】【uva11520】 Fill the Square的更多相关文章
- uva 11520 - Fill the Square
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- Uva 11520 - Fill the Square 贪心 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA 11520 Fill the Square(模拟)
题目链接:https://vjudge.net/problem/UVA-11520 这道题我们发现$n\leq 10$,所以直接进行暴力枚举. 因为根据字典序所以每个位置试一下即可,这样的复杂度不过也 ...
- UVa 11520 Fill the Square 填充正方形
在一个 n * n 网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如果有多重填法,则要求按照从上到下,从左到右的顺序把所有格子连 ...
- UVa 11520 Fill the Square (水题,暴力)
题意:给n*n的格子里填上A-Z的字符,保证相邻字符不同,并且字典序最小. 析:直接从第一个格子开始暴力即可,每次判断上下左是不是相同即可. 代码如下: #pragma comment(linker, ...
- Gym 100531H Problem H. Hiking in the Hills 二分
Problem H. Hiking in the Hills 题目连接: http://codeforces.com/gym/100531/attachments Description Helen ...
- POJ2227(优先队列)
The Wedding Juicer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3440 Accepted: 155 ...
- OI 刷题记录——每周更新
每周日更新 2016.05.29 UVa中国麻将(Chinese Mahjong,Uva 11210) UVa新汉诺塔问题(A Different Task,Uva 10795) NOIP2012同余 ...
- [译]Vulkan教程(29)组合的Image采样器
[译]Vulkan教程(29)组合的Image采样器 Combined image sampler 组合的image采样器 Introduction 入门 We looked at descripto ...
随机推荐
- C# sql操作
SqlConnection con = new SqlConnection(strSqlConnection);//strSqlConnection为字符串连接 DataTable ...
- contentSize、contentInset和contentOffset
contentSize.contentInset和contentOffset 是 scrollView三个基本的属性. contentSize: The size of the content vie ...
- C++重难点知识
1.顶层const和底层const const int a=10; int b=5; const int *p1=&a; int (*const)p2=&b; p1是顶层const,表 ...
- uva 10935 throwing cards away <queue>
Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n ...
- (原)Eclipse的java中文件读写
1 在<uses-sdk…/>下面添加permission <uses-sdk android:minSdkVersion="16" android:target ...
- uploadify ,前端页面获取值,json,ajax
针对这几月的技术,做一次小总结 上传控件uploadify function inexel() { $("#btnExcel").uploadify({ 'method': 'po ...
- POJ3026 最小生成树
问题: POJ3026 分析: 采用BFS算出两两之间的距离,再用PRIM算法计算最小生成树. AC代码: //Memory: 220K Time: 32MS #include <iostrea ...
- iptables中规则的关系——以只允许某些IP段访问为例
最近遇到一个问题:服务器被全球的IP频繁试图通过ssh登录. 于是想到通过iptables防火墙限制访问,达到:仅允许指定ip段访问ssh服务(22端口). 关于iptables添加规则的文章有很多, ...
- 2015网易校招Java开发工程师(技术架构)在线笔试题
1. 程序和进程的本质区别是? A.在外存和内存存储 B.非顺序和顺序执行机器指令 C.独占使用和分时使用计算机资源 D.静态和动态特征 参考答案分析: 进程与应用程序的区别: 进程(Process ...
- [XMPP]简易的聊天室实现[二](使用CocoaAsyncSocket)
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...