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

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

虽然知道了原理,但是并不是特别好做,首先我们需要一次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. tyvj 2054 [Nescafé29]四叶草魔杖【克鲁斯卡尔+状压dp】

    传送:http://www.joyoi.cn/problem/tyvj-2054 来自lyd课件: 所以先预处理出各个sum为0的块,然后状压dfs取min来得到答案 #include<iost ...

  2. bzoj 1603: [Usaco2008 Oct]打谷机【瞎搞】

    一棵树,碰到改变转向的边就异或一下,从1dfs一遍 #include<iostream> #include<cstdio> using namespace std; const ...

  3. [C++ STL] 常用算法总结

    1 概述 STL算法部分主要由头文件<algorithm>,<numeric>,<functional>组成.要使用 STL中的算法函数必须包含头文件<alg ...

  4. fread/fwrite实现复制功能

    1.  fread/fwrite实现复制功能 #include <stdio.h> #include <stdlib.h> #define BUFFSIZE 4096 //执行 ...

  5. C++函数重载的4种错误示例

    函数重载的4种错误示例: #include <iostream> #include <string> using namespace std; //函数重载 同函数名,函数重载 ...

  6. 水题 Codeforces Round #105 (Div. 2) B. Escape

    题目传送门 /* 水题:这题唯一要注意的是要用double,princess可能在一个小时之内被dragon赶上 */ #include <cstdio> #include <alg ...

  7. Node“getTextContent() is undefined for the type Node”处理办法

    最近一个项目在MyEclipse导入后总是报getTextContent() is undefined for the type Node错误. 经过查找原来是因为Node类为JDK中自带的(org. ...

  8. DHTML_____如何编写事件处理程序

    <html> <head> <meta charset="utf-8"> <title>如何编写事件处理程序</title&g ...

  9. SparkContext, map, flatMap, zip以及例程wordcount

    SparkContext 通常作为入口函数,可以创建并返回一个RDD. 如把Spark集群当作服务端那Spark Driver就是客户端,SparkContext则是客户端的核心: 如注释所说 Spa ...

  10. [ Luogu 3935 ] Calculating

    \(\\\) \(Description\) 若\(x\)分解质因数结果为\(x=p_1^{k_1}p_2^{k_2}\cdots p_n^{k_n}\),令\(f(x)=(k_1+1)(k_2+1) ...