题意:识别图中的象形文字。但是,图形可以任意的拉伸,但不能拉断。

分析:这种题如果图形没有特征是不可做类型的题,不过观察图形可以发现每个图形中的洞的数量是一定的,我们只需要数出每一个封闭图形的洞数就能知道这是哪个图形.

虽然知道了原理,但是并不是特别好做,首先我们需要一次dfs将所有图形旁边的点全都变为“不可访问”,然后从每个黑点开始枚举,向四周扩展,遇到白色的块就用第一次的dfs函数覆盖,否则继续第二次dfs,两次dfs交错使用,思路比较巧妙.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; //0表示空白位置,-1表示不能访问了. const int maxn = ; int n, m,kase,a[maxn][maxn],flag[maxn][maxn],cnt,num[maxn];
char s16[] = { '', '', '', '', '', '', '', '', '', '', 'a', 'b', 'c', 'd', 'e', 'f' };
char fuhao[] = { 'A', 'D', 'J', 'K', 'S', 'W' };
int s2[][] =
{
{ , , , }, { , , , }, { , , , }, { , , , },
{ , , , }, { , , , }, { , , , }, { , , , },
{ , , , }, { , , , }, { , , , }, { , , , },
{ , , , }, { , , , }, { , , , }, { , , , }
}; void dfs1(int x,int y)
{
if (x < || x > n + || y < || y > m + || a[x][y] != )
return;
a[x][y] = -;
dfs1(x - , y);
dfs1(x + , y);
dfs1(x, y - );
dfs1(x, y + );
} void dfs2(int x, int y)
{
if (x < || x > n + || y < || y > m + || a[x][y] == -)
return;
if (a[x][y] == )
{
cnt++;
dfs1(x, y);
return;
}
a[x][y] = -;
dfs2(x - , y);
dfs2(x + , y);
dfs2(x, y - );
dfs2(x, y + );
} int main()
{
while (scanf("%d%d", &n, &m) == && (n || m))
{
memset(a, , sizeof(a));
memset(num, , sizeof(num));
for (int i = ; i <= n; i++)
{
getchar();
char ch;
int tot = ;
for (int j = ; j <= m; j++)
{
scanf("%c", &ch);
for (int k = ; k < ; k++)
{
if (ch == s16[k])
{
for (int l = ; l < ; l++)
a[i][++tot] = s2[k][l];
break;
}
}
}
}
m *= ;
dfs1(, );
for (int i = ; i < n; i++)
for (int j = ; j < m; j++)
if (a[i][j] == )
{
cnt = ;
dfs2(i, j);
if (cnt == )
num[]++;
if (cnt == )
num[]++;
if (cnt == )
num[]++;
if (cnt == )
num[]++;
if (cnt == )
num[]++;
if (cnt == )
num[]++;
}
printf("Case %d: ", ++kase);
for (int i = ; i <= ; i++)
{
while (num[i]--)
printf("%c", fuhao[i]);
}
printf("\n");
} return ;
}

Uva1103 Ancient Messages的更多相关文章

  1. K - Ancient Messages(dfs求联通块)

    K - Ancient Messages Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

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

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

  3. UVa 1103 Ancient Messages(二重深搜)

    In order to understand early civilizations, archaeologists often study texts written in ancient lang ...

  4. Ancient Messages UVA - 1103

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

  5. HDU 3839 Ancient Messages(DFS)

    In order to understand early civilizations, archaeologists often study texts written in ancient lang ...

  6. hdu 3839 Ancient Messages (dfs )

    题目大意:给出一幅画,找出里面的象形文字. 要你翻译这幅画,把象形文字按字典序输出. 思路:象形文字有一些特点,分别有0个圈.1个圈.2个圈...5个圈.然后dfs或者bfs,就像油井问题一样,找出在 ...

  7. UVa 1103 (利用连通块来判断字符) Ancient Messages

    本题就是灵活运用DFS来求连通块来求解的. 题意: 给出一幅黑白图像,每行相邻的四个点压缩成一个十六进制的字符.然后还有题中图示的6中古老的字符,按字母表顺序输出这些字符的标号. 分析: 首先图像是被 ...

  8. Uva 1103 Ancient Messages

    大致思路是DFS: 1. 每个图案所包含的白色连通块数量不一: Ankh : 1 ;  Wedjat : 3  ; Djed : 5   ;   Scarab : 4 ; Was : 0  ;  Ak ...

  9. 【例题 6-13 UVA - 1103】Ancient Messages

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每个图案里面的"洞"的个数都是不同的. 则可以根据这个判别每个图像是什么. 先用dfs确定轮廓之后. 再从每个白 ...

随机推荐

  1. spring data elasticsearch的 @Documnet 和 @Field 注解

    @Documnet 注解 public @interface Document { String indexName(); //索引库的名称,个人建议以项目的名称命名 String type() de ...

  2. 2017杭电多校第六场03Inversion

    传送门 Inversion Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  3. ACM_递推题目系列之二认错人(递推dp)

    递推题目系列之二认错人 Time Limit: 2000/1000ms (Java/Others) Problem Description: 国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼 ...

  4. EditText(5)如何控制输入键盘的显示方式及参数表

    参考: https://developer.android.com/training/keyboard-input/visibility.html 1,进入Activity时,EditText就获得焦 ...

  5. Android内存管理(14)*使用开源库LeakCanary检查内存泄漏

    1.简介 它是一个非常简单好用的内存泄漏检测工具库.可以轻松检测Activity,Fragment的内存泄漏.如果有内存泄漏,它会产生一个通知. 2.资料 官网: https://github.com ...

  6. 附加数据库错误代码 - 950【MSSQL】

    分析 (539)代表的是Sql Server 2000数据库的内部版本号,也就是说要附加的数据库文件是由Sql Server 2000创建的,但是我们知道Sql Server 2016 数据库是不兼容 ...

  7. JS在即将离开当前页面(刷新或关闭)时触发事件

    // onbeforeunload 事件在即将离开当前页面(刷新或关闭)时触发 window.onbeforeunload = function () { return /^\#\/ipinfo/.t ...

  8. JDBC和数据库连接池

    JDBC是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成. ​ ● JDBC ​ ● C3P0 ​ ● DRUID 一.JDBC ...

  9. 简单的css缩放动画,仿腾讯新闻的分享按钮和美团app底部的图标样式

    最近看到一些好看的hover的图形缩放效果.然后自己就写了下,发现这2种效果都不错.如果伙伴们更好的实现方式可以在下面留言哦~ 还有美团的效果,我就不展示了,喜欢的可以去app应用上看看. 这两种效果 ...

  10. Farseer.net轻量级开源框架 入门篇:Where条件的终极使用

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 查询数据详解 下一篇:Farseer.net轻量级开源框架 中级篇: 事务的使用 ...