UVA11520(p31)----Fill the Square
来源:互联网 发布:如何安装python 编辑:程序博客网 时间:2024/05/24 05:09
#include<bits/stdc++.h>#define debuusing namespace std;const int maxn=15;int cas=0,n;char g[maxn][maxn];void input(){ printf("Case %d:\n",++cas); scanf("%d\n",&n); for(int i=0; i<n; i++) { for(int j=0; j<n; j++) scanf("%c",&g[i][j]); getchar(); }}void solve(){ for(int i=0; i<n; i++) for(int j=0; j<n; j++) { if(g[i][j]=='.') for(int k=0; k<26; k++) { char ch=k+'A'; if(j>0) if(g[i][j-1]==ch) continue; if(j<n-1) if(g[i][j+1]==ch) continue; if(i>0) if(g[i-1][j]==ch) continue; if(i<n-1) if(g[i+1][j]==ch) continue; //cout<<ch<<endl; g[i][j]=ch; break; } } for(int i=0; i<n; i++) { for(int j=0; j<n; j++) printf("%c",g[i][j]); printf("\n"); }}int main(){#ifdef debug freopen("in.in","r",stdin);#endif // debug int t; scanf("%d",&t); while(t--) { input(); solve(); } return 0;}
题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2515
题解:求从上到下,从左到右字典序最小解。从第一位开始从A到Z尝试(若合法则此解一定字典序最小),由于从A到Z有26字母,而冲突仅有4个,所以一定有解且字典序最小。
0 0
- UVA11520(p31)----Fill the Square
- uva11520 Fill the Square
- uva11520 Fill the Square
- Uva11520 - Fill the Square
- uva11520 - Fill the Square
- uva11520 Fill the Square
- UVa11520-Fill the Square
- uva11520 Fill the Square
- 【贪心】【uva11520】 Fill the Square
- UVA11520 Fill the Square 枚举
- UVA11520 Fill the Square 枚举
- 11520 - Fill the Square
- 11520 - Fill the Square
- Fill the Square
- Fill the Square
- 11520 - Fill the Square
- Fill the Square
- Fill the Square UVA
- android开发建议
- 移动前端头部标签(HTML5 head meta)
- Hibernate
- Hadoop YARN的伪分布式安装
- Hybird App 之 JSBridge
- UVA11520(p31)----Fill the Square
- GNU C 与 ANSI C的区别
- Java连接数据库
- 【C++】C++发展和特性
- this project needs to migrate WTP metadata 异常解决办法
- 2015年工作总结——①名IT女的日常
- CKEditor配置
- sqlite数据库的char,varchar,text,nchar,nvarchar,ntext的区别
- php预防XSS