Uva1103 Ancient Messages
题意:识别图中的象形文字。但是,图形可以任意的拉伸,但不能拉断。
分析:这种题如果图形没有特征是不可做类型的题,不过观察图形可以发现每个图形中的洞的数量是一定的,我们只需要数出每一个封闭图形的洞数就能知道这是哪个图形.
虽然知道了原理,但是并不是特别好做,首先我们需要一次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的更多相关文章
- K - Ancient Messages(dfs求联通块)
K - Ancient Messages Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Subm ...
- UVA1103 古代象形符号 Ancient Messages 题解
题目链接: https://www.luogu.org/problemnew/show/UVA1103 题目分析: 我们可以先进行矩阵的还原 for(int k=1;k<=4;k++) { a[ ...
- UVa 1103 Ancient Messages(二重深搜)
In order to understand early civilizations, archaeologists often study texts written in ancient lang ...
- Ancient Messages UVA - 1103
题目链接:https://vjudge.net/problem/UVA-1103 题目大意:每组数据包含H行W列的字符矩阵(H<=200,W<=50) 每个字符为为16进制 你需要把它转 ...
- HDU 3839 Ancient Messages(DFS)
In order to understand early civilizations, archaeologists often study texts written in ancient lang ...
- hdu 3839 Ancient Messages (dfs )
题目大意:给出一幅画,找出里面的象形文字. 要你翻译这幅画,把象形文字按字典序输出. 思路:象形文字有一些特点,分别有0个圈.1个圈.2个圈...5个圈.然后dfs或者bfs,就像油井问题一样,找出在 ...
- UVa 1103 (利用连通块来判断字符) Ancient Messages
本题就是灵活运用DFS来求连通块来求解的. 题意: 给出一幅黑白图像,每行相邻的四个点压缩成一个十六进制的字符.然后还有题中图示的6中古老的字符,按字母表顺序输出这些字符的标号. 分析: 首先图像是被 ...
- Uva 1103 Ancient Messages
大致思路是DFS: 1. 每个图案所包含的白色连通块数量不一: Ankh : 1 ; Wedjat : 3 ; Djed : 5 ; Scarab : 4 ; Was : 0 ; Ak ...
- 【例题 6-13 UVA - 1103】Ancient Messages
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每个图案里面的"洞"的个数都是不同的. 则可以根据这个判别每个图像是什么. 先用dfs确定轮廓之后. 再从每个白 ...
随机推荐
- phpAnalysis调试接口
phpAnalysis是一款轻量级非侵入式PHP应用性能分析器,适用于开发.测试及生产环境部署使用,方便开发及测试工程师诊断性能问题: 通过tideways收集PHP程序单步运行过程中所有的函数调用时 ...
- MvcPager 分页控件
官方教程: http://www.webdiyer.com/mvcpager
- C基础-对malloc的使用与理解
一.malloc函数分析 1.函数原型 void * malloc(size_t size); 2.Function(功能) Allocates a block of size bytes of m ...
- [POJ3417]Network/闇の連鎖
Description 传说中的暗之连锁被人们称为 Dark. Dark 是人类内心的黑暗的产物,古今中外的勇者们都试图打倒它.经过研究,你发现 Dark 呈现无向图的结构,图中有 N 个节点和两类边 ...
- pyCharm最新激活码(2018)
1.修改hosts文件: 添加下面一行到hosts文件,目的是屏蔽掉Pycharm对激活码的验证 0.0.0.0 account.jetbrains.com windwos系统hosts文件路径为:C ...
- python之路 之一pyspark
pip包下载安装pyspark pip install pyspark 这里可能会遇到安装超时的情况 加参数 --timeout=100 pip -default -timeout=1 ...
- 引入css的四种方式
1.内联式引用:直接用在标签上,但维护成本高 style='font-size:16px;color:#000000' 2.外部连接式引用:css代码与html代码分离,便于代码重复使用 <li ...
- Pro ASP.NET Core MVC 第6版 第二章(前半章)
目录 第二章 第一个MVC 应用程序 学习一个软件开发框架的最好方法是跳进他的内部并使用它.在本章,你将用ASP.NET Core MVC创建一个简单的数据登录应用.我将它一步一步地展示,以便你能看清 ...
- JSP学习笔记 - 内置对象 Response
1.response.addHeader("refresh","2"): 制定页面刷新时间 2.response.addHeader("refresh ...
- Masonry基础API
Masonry基础API mas_makeConstraints() 添加约束 mas_remakeConstraints() 移除之前的约束,重新添加新的约束 mas_updateConst ...