题意:输入以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的更多相关文章

  1. UVA1103 古代象形符号 Ancient Messages 题解

    题目链接: https://www.luogu.org/problemnew/show/UVA1103 题目分析: 我们可以先进行矩阵的还原 for(int k=1;k<=4;k++) { a[ ...

  2. Uva1103 Ancient Messages

    题意:识别图中的象形文字.但是,图形可以任意的拉伸,但不能拉断. 分析:这种题如果图形没有特征是不可做类型的题,不过观察图形可以发现每个图形中的洞的数量是一定的,我们只需要数出每一个封闭图形的洞数就能 ...

  3. 6_13古代象形符号(UVa1103)<图的连通块的应用>

    给出一幅黑白图像,每行相邻的四个点压缩成一个十六进制的字符.然后还有题中图示的6中古老的字符,按字母表顺序输出这些字符的标号. 输出说明:For each test case, display its ...

  4. 这个随笔用用来放一些好的思想和思考方式(暂时secret)

    一: 给你一个只有4和7的数字,求这是第几个幸运数字? 思路: 我们把4映射成0,7映射成1,然后就如下枚举:0,1,00,01,10,11.因为是映射的,所以可以前导0,然后我们就会知道给出的那个数 ...

  5. Ancient Messages UVA - 1103

    题目链接:https://vjudge.net/problem/UVA-1103 题目大意:每组数据包含H行W列的字符矩阵(H<=200,W<=50) 每个字符为为16进制  你需要把它转 ...

  6. LRJ-Example-06-13-Uva1103

    pic[][]数组存储每个点的值,0或1,输入时在原图的周围加了一圈0. color[][]数组存储每个点的color值,从1开始,dfs(row, col, c) 负责对每个点着色,连通在一起的连通 ...

随机推荐

  1. memcpy函数用法

    memcpy函数用法 .分类: VC++ VC++ mfc matlab 2011-12-01 19:17 14538人阅读 评论(0) 收藏 举报 null 原型:extern void *memc ...

  2. multipath tcp experiment

    git clone https://github.com/Neohapsis/mptcp-abuse.git sudo apt-get install python-pip sudo pip inst ...

  3. 今天第一节PS课

  4. 自顶而下设计FPGA

    对IC设计而言,FPGA设计层级大致包括:系统级和行为级,RTL级,门级和晶体管级.然而更普遍的情况,FPGA只是用作实时数据采集控制.某些快速处理算法.PCIe\DDR3等高速数据通道,甚至某些简单 ...

  5. windows上传代码到github

    上传代码到github上有很多种方法,在这里我介绍一种比较简单的一种.工具嘛,越简单越好用啊. 1.首先下载github在windows下的客户端 下载地址:https://desktop.githu ...

  6. ubuntu下修改进入root用户和修改文件权限

    (1)进入root用户 su root 密码:设置的root密码 (2)修改文件权限 sudo chmod +777  file (3)执行shell ./shellfile (4)编写shell 第 ...

  7. 关于ASPXGridview的双击事件弹出 【转】

    在网上找了好长时间,关于ASPXGridview的双击事件弹出ASPxPopupControl,也没有找到适合自己的代码,这里将自己编写出来的代码与大家分享一下 希望我的代码能够对你有所帮助. 直接上 ...

  8. 第9章 硬件抽象层:HAL

    HAL(硬件抽象层)是建立在Linux驱动之上的一套程序库.这套程序库并不属于Linux内核,而是属于Linux内核层之上的应用层.在传统的Linux系统中Linux驱动一般有两种类型的代码:访问硬件 ...

  9. window.onload、DOMContentLoaded和$(document).ready()

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...

  10. jenkins之安装篇

    自动化学习过程中老师介绍了一个工具jenkins,感觉很不错,学习ingjenkins的war包下载地址http://mirrors.jenkins-ci.org/war/Hudson的war包下载地 ...