题意:输入以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. SQL Server中cursor的使用步骤

    参考文章: http://www.cnblogs.com/knowledgesea/p/3699851.html http://www.cnblogs.com/moss_tan_jun/archive ...

  2. 程序内部让用户直接上appstore评价游戏的链接地址以及跳转方法

    NSString *str = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore ...

  3. web.config 配置

    一.认识Web.config文件   Web.config 文件是一个xml文本文件,它用来储存 asp.NET Web 应用程序的配置信息(如最常用的设置asp.NET Web 应用程序的身份验证方 ...

  4. SQL Server 内置函数、临时对象、流程控制

    SQL Server 内置函数 日期时间函数 --返回当前系统日期时间 select getdate() as [datetime],sysdatetime() as [datetime2] getd ...

  5. 微信Auth2.0授权的时候出现两次回调

    在获取用户OpenID的时候 $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".WX_APPID. ...

  6. C 计算数组长度

    int data[4],length; length=sizeof(data)/sizeof(data[0]);  //数组占内存总空间除以单个元素占内存空间大小,即等于元素个数 printf(&qu ...

  7. 3dsMax用到的网格优化

    3dsMax软件主要是用于建模的,里面有一个网格优化的功能,它的网格优化的过程是基于那个网格简化算法,经过使用个人认为是基于几何删除的折叠方式来进行的,可能是边折叠或者三角折叠的方式,还望大神多多指教 ...

  8. js日期重写

    Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d ...

  9. hash表C语言实现

    算法参考<算法导论>第11章散列表.采用链地址法解决冲突. #include <stdio.h> #include <stdlib.h> #include < ...

  10. C#窗体无法接受Keydown事件

    问题一描述:当新建一个窗体时,添加KeyDown事件后,会正常处理,但是当添加有控件时,比如Button,TextBox,不会触发窗体的KeyDown事件,也没有调用KeyDown事件的处理程序. 原 ...