HDU 3839 Ancient Messages(DFS)

Input
- The image contains only hieroglyphs shown in Figure C.1.
- Each image contains at least one valid hieroglyph.
- Each black pixel in the image is part of a valid hieroglyph.
- Each hieroglyph consists of a connected set of black pixels and each black pixel has at least one other black pixel on its top, bottom, left, or right side.
- The hieroglyphs do not touch and no hieroglyph is inside another hieroglyph.
- Two black pixels that touch diagonally will always have a common touching black pixel.
- The hieroglyphs may be distorted but each has a shape that is topologically equivalent to one of the symbols in Figure C.11.
The last test case is followed by a line containing two zeros.
1Two figures are topologically equivalent if each can be transformed into the other by stretching without tearing.
Output
Ankh: A
Wedjat: J
Djed: D
Scarab: S
Was: W
Akhet: K
In each output string, print the codes in alphabetic order. Follow the format of the sample output.
The sample input contains descriptions of test cases shown in Figures C.2 and C.3. Due to space constraints not all of the sample input can be shown on this page.
Sample Input
100 25
0000000000000000000000000
0000000000000000000000000
...(50 lines omitted)...
00001fe0000000000007c0000
00003fe0000000000007c0000
...(44 lines omitted)...
0000000000000000000000000
0000000000000000000000000
150 38
00000000000000000000000000000000000000
00000000000000000000000000000000000000
...(75 lines omitted)...
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
...(69 lines omitted)...
00000000000000000000000000000000000000
00000000000000000000000000000000000000
0 0
Sample Output
Case 1: AKW
Case 2: AAAAA 题意:给出十六进制的数字矩阵,对其转换为二进制矩阵,输出转换后图像中按字典序排列的象形文字名。 解题思路:给出的象形文字的中间洞数各不相同(那就可以操作一波了,那么只要先找到字,在找出该字内部有几个洞即可确定象形字母的类型,首先去除字外的0,将其标为-1,
这里有个小操作是把存的图像外圈围一圈0,这样就可以直接从(0,0)点dfs对字外的0改标记为1,然后再遍历数组找1,即找字,找到字后将字内的0同样标上-1,并计算空洞数,
同时将字上的1全部转换(相当于遍历过这里的标记),确定这个字之后将其压入vector数组,最后结果对vector数组排序并输出即可。
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <set>
#include <vector>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <climits>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
#define INF 0X3f3f3f3f
const ll MAXN = 1e5 + ;
const ll MOD = 1e9 + ;
char trans[] = {'', '', '', '', '', '', '', '', '', '', 'a', 'b', 'c', 'd', 'e', 'f'};
int transto[][] = {
{, , , }, {, , , }, {, , , }, {, , , },
{, , , }, {, , , }, {, , , }, {, , , },
{, , , }, {, , , }, {, , , }, {, , , },
{, , , }, {, , , }, {, , , }, {, , , }
};
int maze[][];
int dir[][] = {{, }, {, }, {-, }, {, -}};
char ans[] = {'W', 'A', 'K', 'J', 'S', 'D'};
int n, m, cnt=;
bool check(int x, int y)
{
if (x >= && x <= n+ && y >= && y <= + * m)
return true;
return false;
}
void dfs_vis(int x, int y) //将字外0标为-1
{
if (!check(x, y)||maze[x][y])
return;
maze[x][y] = -; //在字外面的0标为-1
for (int i = ; i < ; i++)
dfs_vis(x + dir[i][], y + dir[i][]);
}
void dfs_bak(int x, int y) //找字的空白块
{
if (!check(x, y) ||maze[x][y] == - || maze[x][y] == )
return;
if (maze[x][y] == )
{
cnt++;
dfs_vis(x, y);
}
else
{
maze[x][y] = ;
for (int i = ; i < ; i++)
dfs_bak(x + dir[i][], y + dir[i][]);
}
return;
}
void debug()
{
for (int i = ; i <= n+; i++)
{
for (int j = ; j <=+ * m; j++)
cout << maze[i][j];
cout << endl;
}
return;
}
int main()
{
ios::sync_with_stdio(false);
int t = ;
while (cin >> n >> m && n && m)
{
vector<char> vec;
memset(maze, , sizeof(maze));
for (int i = ; i < n; i++)
{
char temp[];
cin >> temp;
int cnt = ;
for (int i1 = ; i1 < m; i1++)
{
for (int j = ; j < ; j++)
{
if (trans[j] == temp[i1])
{
for (int k = ; k < ; k++)
maze[i+][cnt++] = transto[j][k];
break;
}
}
}
}
// debug();
dfs_vis(,);
for (int i = ; i <= n; i++)
{
for (int j = ; j <= *m+; j++)
{
if (maze[i][j] == )
{
dfs_bak(i, j);
vec.push_back(ans[cnt]);
cnt=;
// debug();
}
}
}
sort(vec.begin(), vec.end());
cout << "Case " << t++ << ": ";
vector<char>::iterator it;
for (it = vec.begin(); it != vec.end(); it++)
cout << *it;
cout << endl;
}
return ;
}
/* A-1 J-3 D-5 S-4 W-0 K-2*/
再给出两组数据方便自行debug:
100 25
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
00000f8000000000000000000
00001fe000000000000000000
00007ff000000000000000000
00007ff800000000000000000
0000f8f800000000000000000
0001f07c00000000000000000
0001e03c00000000001800000
0001e01c00000000003c00000
0001c01c00000000007c00000
0003c01e0000000000f800000
0003c01e0000000001f000000
0001c01c0000000003f000000
0001c01c0000000007e000000
0001e01c000000000fc000000
0001e03c000000001fc000000
0000e03c000000001fc000000
0000f038000000003ff000000
0000f078000000003ff800000
00007870000000007ff800000
000038f0000000007cfc00000
00003ce0000000007c7c00000
00781fc0f0000000f87c00000
007ffffff0000000f07c00000
007ffffff0000000f07c00000
007ffffff0000001f07c00000
007ffffff0000000e03e00000
007fcf81f0000000603e00000
00000f8000000000003e00000
00000f8000000000003e00000
00000f8000000000003e00000
00000f8000000000001e00000
00000f8000000000001f00000
00000fc000000000001f00000
00000fc000000000001f00000
00000fc000000000001f00000
00000fc000000000000f00000
00001fc000000000000f80000
00001fc000000000000f80000
00001fc000000000000f80000
00001fc000000000000f80000
00001fe000000000000f80000
00001fe000000000000780000
00001fe0000000000007c0000
00001fe0000000000007c0000
00003fe0000000000007c0000
00003fe0000000000007c0000
00003fe0000000000007c0000
00003fe0000c00000003c0000
00000000003ff0000003c0000
00000000007ff8000003e0000
0000000001fffc000003e0000
0000000003e03f000003e0000
0000000007c00f000003e0000
000000000f0003800003f0000
000000000e0001c00003fc000
000000001c0001e00007fe000
000000003c0000e0000fff000
000000073c000070000fdf000
0000001ff8000070001f0f800
0000001ff8000070001e07800
0000003cf0000078001e03800
0000003870000033001e03800
000000307800003fc01e03800
000000703800007fe00e03800
000000703800007ce00e03800
000000703c000078700703800
000000701e0000f0700701000
000000701e0000e0700300000
000000700f0001c0700000000
0000006007800380600000000
000000e003e00700600000000
000000e001fe7e00600000000
000000e000fffc00e00000000
000000e0000ff000e00000000
000000f800038000e00000000
000000fff0000000e00000000
000000fffff00000e00000000
00000003ffffe000c00000000
0000000007ffffc0c00000000
000000000007ffffc00000000
0000000000000fffc00000000
000000000000001fc00000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
150 38
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000f80000000001fff000000000000000000
00001fe0000000007fff800000000000000000
00007ff000000000ffffe00000000000000000
00007ff800000003fffff0000000007c000000
0000f8f800000007fffffc00000000fe000000
0001f07c0000000ffffffe00000001ff000000
0001e03c0000001fffffff00000003ff800000
0001e01c0000003fffffff00000003ffc00000
0001c01c0000003fffffff80000007efc00000
0003c01e0000007fffffffc000000783c00000
0003c01e000000ffffffffc000000f81e00000
0001c01c000000fffc0fffe000000f01e00000
0001c01c000001fff003ffe000000f01e00000
0001e01c000001ffe001fff000000f00e00000
0001e03c000003ffc0007ff000001e00f00000
0000e03c000003ff80007ff800001e00f00000
0000f038000007ff80003ff800001e00f00000
0000f078000007ff00003ff800001e00f00000
00007870000007ff00001ffc00000e00e00000
000038f000000fff00001ffc00000e00e00000
00003ce000000ffe00000ffc00000e00e00000
00781fc0f0000ffe00000ffc00000f00e00000
007ffffff0000ffc00000ffc00000f01e00000
007ffffff0000ffc00000ffc00000f01e00000
007ffffff0000ffc00000ffc00000701c00000
007ffffff0000ffc00000ffc00000781c00000
007fcf81f0000ffc000007fc00000783c00000
00000f8000000ffc000007fc00000383800000
00000f8000000ffc000007fc000003c7800000
00000f8000000ffc000007fc000001c7800000
00000f8000000ffc000007fc000001e7000000
00000f8000000ffc000007fc000200ef008000
00000fc000000ffc00000ffc0003f8fe3f8000
00000fc000000ffc00000ffc0003ffffff8000
00000fc000000ffc00000ffc0003ffffff8000
00000fc000000ffc00000ffc0003ffffff8000
00001fc000000ffc00000ffc0003ffffff8000
00001fc0000007fe00000ff80003ffffff8000
00001fc0000007fe00000ff80003fffdff8000
00001fc0000007fe00000ff80003c03c000000
00001fe0000007ff00001ff80000007c000000
00001fe0000003ff00001ff00000007c000000
00001fe0000003ff00001ff00000007c000000
00001fe0000001ff80003ff00000007c000000
00003fe0000001ff80003fe00000007c000000
00003fe0000001ff80003fe00000007c000000
00003fe0000000ffc0007fe00000007c000000
00003fe0000000ffc0007fc00000007e000000
000000000000007fe0007fc00000007e000000
000000000000007fe000ff800000007e000000
000000000000007ff001ff800000007e000000
000000000000003ff001ff80000000fe000000
000000000000001ff803ff00000000fe000000
000000000000001ff803ff00000000fe000000
000000000000000ffc07fe00000000fe000000
000000000000000ffc0ffc00000000fe000000
000000000000000ffe0ffc00000000fe000000
0000000000000007ff0ff800000000fe000000
0000000000000003ff1ff000000000ff000000
0000000003c00001ffbff00000f000ff000000
0000000003ffc001ffffe0007ff000ff000000
0000000003fffff1ffffe3fffff000ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffc1ffe0007fff00000000000
0000000003ff80000ffe000000f00000000000
00000000038000000ffe000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000003fff000000000000000000
00000000000000003fff000000000000000000
00000000000000003fff0000000fc000000000
000000000fe000003fff8000003ff000000000
000000003ffc00003fff8000007ffc00000000
00000000fffe00003fff800000fcfc00000000
00000001f01f00003fff800001f03e00000000
00000003e00f80003fff800003e01f00000000
00000003e00780003fff800003e00f00000000
00000003e00780003fff800003c00f00000000
00000003e00f80003fff800003c00f00000000
00000001f00f00007fff800003c00f00000000
00000000f81e00007fffc00003e00f00000000
000000007c3c00007fffc00001e01e00000000
000000003e7800007fffc00000f01e00000000
000000fffffffe007fffc00000f03c00000000
000000fffffffe007fffc00000787800000000
000000fffffffe007fffc000003cf000000000
0000000007c000007fffe000f81fe07c000000
0000000007e000007fffe000fffffffc000000
0000000007e000007fffe000fffffffc000000
000000000fe000007fffe000fffffffc000000
000000000ff00000ffffe000ffc7c0fc000000
000000000ff00000ffffe0000007c000000000
000000001ff00000ffffe000000fc000000000
000000001ff00000ffffe000000fc000000000
000000001ff80000ffffe000000fc000000000
000000001ff80000ffffe000000fc000000000
000000003ff80001ffffe000000fe000000000
000000003ff80001ffffe000000fe000000000
0000000000000001fffff000001fe000000000
0000000000000001fffff000001fe000000000
0000000000000001fffff000001fe000000000
0000000000000001fffff000001ff000000000
0000000000000001fffff000001ff000000000
0000000000000001fffff000001ff000000000
0000000000000001fffff000003ff000000000
0000000000000001fffff000003ff000000000
0000000000000001fffff000003ff000000000
0000000000000001fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffffc0000000000000000
0000000000000003fffffc0000000000000000
0000000000000007fffffc0000000000000000
0000000000000007fffffc0000000000000000
0000000000000007fffffc0000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
Case 1: AKW
Case 2: AAAAA
HDU 3839 Ancient Messages(DFS)的更多相关文章
- hdu 3839 Ancient Messages (dfs )
题目大意:给出一幅画,找出里面的象形文字. 要你翻译这幅画,把象形文字按字典序输出. 思路:象形文字有一些特点,分别有0个圈.1个圈.2个圈...5个圈.然后dfs或者bfs,就像油井问题一样,找出在 ...
- 2017ACM暑期多校联合训练 - Team 1 1003 HDU 6035 Colorful Tree (dfs)
题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented ...
- hdu 1716 排序2(dfs)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 2660 Accepted Necklace(dfs)
Problem Description I have N precious stones, and plan to use K of them to make a necklace for my mo ...
- HDU 4414 Finding crosses(dfs)
Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- UVA - 1103Ancient Messages(dfs)
UVA - 1103Ancient Messages In order to understand early civilizations, archaeologists often study te ...
- HDU 6351 Beautiful Now(DFS)多校题解
思路:一开始对k没有理解好,题意说交换k次,如果我们不需要交换那么多,那么可以重复自己交换自己,那么k其实可以理解为最多交换k次.这道题dfs暴力就行,我们按照全排列最大最小去找每一位应该和后面哪一位 ...
- HDU 5952 Counting Cliques(dfs)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
随机推荐
- pycharm 设置代码折叠和展开(mac)
折叠/展开 pycharm设置 点击PyCharm--->Preferences--->Editor--->General--->Code Folding,勾选Show cod ...
- $vjudge-dp$专题题解
因为感觉题解写不了多少,,,就懒得一道道题目慢慢写了,汇总了算了$QAQ$ 昂然后因为我估计以后还会有些什么$dp$专题啊$balabala$的,,,然后谢总肯定又会建一堆小组啥的,,,所以还是放个链 ...
- MyBatis原理-架构流程
一 .MyBatis原理架构图 Mybatis的功能架构分为三层: API接口层:提供给外部使用的接口API,开发人员通过这些本地API来操纵数据库.接口层一接收到调用请求就会调用数据处理层来完成具体 ...
- Java日志体系居然这么复杂?——架构篇
本文是一个系列,欢迎关注 日志到底是何方神圣?为什么要使用日志框架? 想必大家都有过使用System.out来进行输出调试,开发开发环境下这样做当然很方便,但是线上这样做就有麻烦了: 系统一直运行,输 ...
- AES Base64 C++加密工具
最近写了一段C++ 的AES 加密的工具,在github 上找了很多工具,都不太好用,Star数字比较的高的一个,只能加密16个字节的,加密数字长数据,会出现乱码,不能使用 这里附上代码,文件以供大家 ...
- 1065 单身狗 (25分)C语言
单身狗"是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式: 输入第一行给出一个正整数 N(≤ 50 000),是已知夫妻/伴侣的对数:随 ...
- Longhorn入门级教程!轻松实现持久化存储!
介 绍 在本文中你将学会如何使用k3s在Civo上运行Longhorn.如果你还没使用过Civo,可以到官网注册(https://www.civo.com/ )还可以申请免费的使用额度.首先,需要一个 ...
- 揭秘webpack plugin
前言 Plugin(插件) 是 webpack 生态的的一个关键部分.它为社区提供了一种强大的方法来扩展 webpack 和开发 webpack 的编译过程.这篇文章将尝试探索 webpack plu ...
- python列表的方法(改变原列表)
xxx.append() 末尾添加一个元素效果图: 代码: # append() 末尾添加一个元素 my_list = ['] print('原列表:',my_list) my_list.a ...
- 【C_Language】---C语言const用法总结
C语言关键字const相信对于不少C语言新手是既陌生又熟悉的,好像经常见,但是却不知道为何用,怎么用?学习至此,总结一下const的用法,使用程序来帮助你理解该关键字,希望能帮到像我一样的新手. 我看 ...