UVA1103
题意:输入以16进制的矩阵,先转换成2进制,之后输出形成的图案。
思路:先处理掉无关图案的0,之后一个图案一个图案的遍历,识别图案的方法就是有多少个圈圈。找到一个就全部标记为-1。并且记录圆圈的数目。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm> using namespace std; int gragh[][];
int dir[][] = {{-,},{,},{,},{,-}};
char s[];
int n,m,ans; void change(char c,int i,int j)
{
if(c >= '' && c <= ''){
int a = c - '';
gragh[i][(j-)*+] = a%;a /= ;
gragh[i][(j-)*+] = a%;a /= ;
gragh[i][(j-)*+] = a%;a /= ;
gragh[i][(j-)*+] = a%;
}
else {
int a = c - 'a' + ;
gragh[i][(j-)*+] = a%;a /= ;
gragh[i][(j-)*+] = a%;a /= ;
gragh[i][(j-)*+] = a%;a /= ;
gragh[i][(j-)*+] = a%;
}
} void dfs1(int x,int y)
{
gragh[x][y] = -;
for(int i = ;i < ; i++){
int xx = x + dir[i][];
int yy = y + dir[i][];
if(xx >= && xx <= n && yy >= && yy <= m && gragh[xx][yy] == ){
dfs1(xx,yy);
}
}
} void dfs2(int x,int y)
{
gragh[x][y] = -;
for(int i = ;i < ; i++){
int xx = x + dir[i][];
int yy = y + dir[i][];
if(xx >= && xx <= n && yy >= && yy <= m && gragh[xx][yy] == ){
dfs1(xx,yy);
ans++;
}
else if(xx >= && xx <= n && yy >= && yy <= m && gragh[xx][yy] == ){
dfs2(xx,yy);
}
}
} int main()
{
// freopen("in.txt","r",stdin);
int ncase = ;
while(scanf("%d%d",&n,&m) != EOF){
if(n == && m == )
break; memset(gragh,,sizeof(gragh));
memset(s,,sizeof(s));
char c[];
for(int i = ;i <= n; i++){
scanf("%s",c+);
for(int j = m;j >= ; j--){
change(c[j],i,j);
}
}
m *=; for(int i = ;i <= n; i++){
if(gragh[i][] == )
dfs1(i,);
if(gragh[i][m] == )
dfs1(i,m);
}
for(int j = ;j <= m; j++){
if(gragh[][j] == )
dfs1(,j);
if(gragh[n][j] == )
dfs1(n,j);
}
int pos = ;
for(int i = ;i <= n; i++){
for(int j = ;j <= m; j++){
if(gragh[i][j] == ){
ans = ;
dfs2(i,j);
if(ans == ){
s[pos++] = 'A';
}
else if(ans == )
s[pos++] = 'J';
else if(ans == )
s[pos++] = 'D';
else if(ans == )
s[pos++] = 'S';
else if(ans == )
s[pos++] = 'W';
else if(ans == )
s[pos++] = 'K';
}
}
} sort(s,s+pos);
printf("Case %d: ",ncase++);
for(int i = ;i < pos; i++)
printf("%c",s[i]);
printf("\n");
}
return ;
}
UVA1103的更多相关文章
- UVA1103 古代象形符号 Ancient Messages 题解
题目链接: https://www.luogu.org/problemnew/show/UVA1103 题目分析: 我们可以先进行矩阵的还原 for(int k=1;k<=4;k++) { a[ ...
- Uva1103 Ancient Messages
题意:识别图中的象形文字.但是,图形可以任意的拉伸,但不能拉断. 分析:这种题如果图形没有特征是不可做类型的题,不过观察图形可以发现每个图形中的洞的数量是一定的,我们只需要数出每一个封闭图形的洞数就能 ...
- 6_13古代象形符号(UVa1103)<图的连通块的应用>
给出一幅黑白图像,每行相邻的四个点压缩成一个十六进制的字符.然后还有题中图示的6中古老的字符,按字母表顺序输出这些字符的标号. 输出说明:For each test case, display its ...
- 这个随笔用用来放一些好的思想和思考方式(暂时secret)
一: 给你一个只有4和7的数字,求这是第几个幸运数字? 思路: 我们把4映射成0,7映射成1,然后就如下枚举:0,1,00,01,10,11.因为是映射的,所以可以前导0,然后我们就会知道给出的那个数 ...
- Ancient Messages UVA - 1103
题目链接:https://vjudge.net/problem/UVA-1103 题目大意:每组数据包含H行W列的字符矩阵(H<=200,W<=50) 每个字符为为16进制 你需要把它转 ...
- LRJ-Example-06-13-Uva1103
pic[][]数组存储每个点的值,0或1,输入时在原图的周围加了一圈0. color[][]数组存储每个点的color值,从1开始,dfs(row, col, c) 负责对每个点着色,连通在一起的连通 ...
随机推荐
- fc23升级fc24及字体问题解决
1,升级fc23到最新 dnf upgrade --refresh 2,安装dnf系统升级插件 dnf install dnf-plugin-system-upgrade 3,下载fc24包,忽略无法 ...
- 再读C++线程池
最近仔细看了一下https://github.com/henkel/threadpool代码,总体感觉非常精巧,使用了 boost库的bind function完成了线程池与业务端的完全解耦:所有的任 ...
- 添加网络打印机的步骤(xp和win2008)
1.如题,设置好打印机去的ip地址和子网掩码等信息. 2 .xp不像其他新的系统那么好用那么智能...只能慢慢来 如果是xp,注意,请添加网络打印机的时候选 :添加本地打印机,,记得哦 然后如图 然 ...
- a标签的herf和click事件
在动态网页中,常常需要在单击超链接时处理一些数据,而不是跳转一个网页.在这种情况下,通常有以下三种处理方式: 不设置<a>标签的href属性,只设置onclick属性.在这种处理方式下,通 ...
- python进阶笔记 thread 和 threading模块学习
Python通过两个标准库thread和threading提供对线程的支持.thread提供了低级别的.原始的线程以及一个简单的锁.threading基于Java的线程模型设计.锁(Lock)和条件变 ...
- 使用vs2010创建MFC C++ Ribbon程序
Your First MFC C++ Ribbon Application with Visual Studio 2010 Earlier this month, I put together my ...
- jpa 表字段转bean对象
select 'private ' || decode(v_type, 'int', 'Integer', 'float', 'Double', 'date', 'Date', 'String') | ...
- iOS保存cookie的方法
SURLRequest*request =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/ ...
- Oracle对列的操作总结
1.更改列名 alter table TABLE_NAME rename column COLUMN_OLD COLUMN_NEW; 2.添加列 alter table TABLE_NAME add ...
- Unity3D 处理Label的颜色代码
UILabel m_name = transform.Find("Name").GetComponent<UILabel>(); m_name.text = GetNa ...