Problem Description
In order to understand early civilizations, archaeologists often study texts written in ancient languages. One such language, used in Egypt more than 3000 years ago, is based on characters called hieroglyphs. Figure C.1 shows six
hieroglyphs and their names. In this problem, you will write a program to recognize these six characters.

 
Input
The input consists of several test cases, each of which describes an image containing one or more hieroglyphs chosen from among those shown in Figure C.1. The image is given in the form of a series of horizontal scan lines consisting
of black pixels (represented by 1) and white pixels (represented by 0). In the input data, each scan line is encoded in hexadecimal notation. For example, the sequence of eight pixels 10011100 (one black pixel, followed by two white pixels, and so on) would
be represented in hexadecimal notation as 9c. Only digits and lowercase letters a through f are used in the hexadecimal encoding. The first line of each test case contains two integers, H and W: H (0 < H <= 200) is the number of scan lines in the image. W
(0 < W <= 50) is the number of hexadecimal characters in each line. The next H lines contain the hexadecimal characters of the image, working from top to bottom. Input images conform to the following rules:

  • 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
For each test case, display its case number followed by a string containing one character for each hieroglyph recognized in the image, using the following code:



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
 
Source

思路:依据圈的数量来识别。

#include <cstdio>
#include <algorithm>
using namespace std; char ts[201],mes[6]={'W','A','K','J','S','D'},ans[10];
bool vis[205][205];
int n,m,mp[205][205],nxt[4][2]={{1,0},{0,1},{-1,0},{0,-1}},num; void dfs(int x,int y)
{
int i; for(i=0;i<4;i++)
{
x+=nxt[i][0];
y+=nxt[i][1]; if(x>=0 && x<n && y>=0 && y<m && !vis[x][y] && !mp[x][y])
{
vis[x][y]=1;
dfs(x,y);
} x-=nxt[i][0];
y-=nxt[i][1];
}
} void dfs3(int x,int y)
{
int i; for(i=0;i<4;i++)
{
x+=nxt[i][0];
y+=nxt[i][1]; if(x>=0 && x<n && y>=0 && y<m && !vis[x][y] && !mp[x][y])
{
vis[x][y]=1;
dfs3(x,y);
} x-=nxt[i][0];
y-=nxt[i][1];
}
} void dfs2(int x,int y)
{
int i; for(i=0;i<4;i++)
{
x+=nxt[i][0];
y+=nxt[i][1]; if(x>=0 && x<n && y>=0 && y<m && !vis[x][y])
{
if(mp[x][y])
{
vis[x][y]=1;
dfs2(x,y);
}
else
{
vis[x][y]=1;
num++;
dfs3(x,y);
} } x-=nxt[i][0];
y-=nxt[i][1];
}
} int main()
{
int i,j,t,casenum=1,cnt; while(~scanf("%d%d",&n,&m) && n)
{
n++;
m*=4;
m++; for(i=0;i<=n;i++) for(j=0;j<=m;j++) vis[i][j]=0; for(i=1;i<n;i++)
{
gets(ts); if(!ts[0])
{
i--;
continue;
} for(j=0;ts[j];j++)
{
if(ts[j]>='a' && ts[j]<='f')
{
t=ts[j]-'a'+10; mp[i][j*4+1]=t/8;
mp[i][j*4+2]=t%8/4;
mp[i][j*4+3]=t%4/2;
mp[i][j*4+4]=t%2/1;
}
else
{
t=ts[j]-'0'; mp[i][j*4+1]=t/8;
mp[i][j*4+2]=t%8/4;
mp[i][j*4+3]=t%4/2;
mp[i][j*4+4]=t%2/1;
}
}
} for(i=0;i<=m;i++) mp[n][i]=0;
for(i=0;i<=n;i++) mp[i][m]=0; n++;
m++; vis[0][0]=1;
dfs(0,0); cnt=0; for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(mp[i][j] && !vis[i][j])
{
num=0; vis[i][j]=1; dfs2(i,j); ans[cnt++]=mes[num];
}
}
} sort(ans,ans+cnt); ans[cnt]=0; printf("Case %d: ",casenum++); puts(ans);
}
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU-3839-Ancient Messages(DFS)的更多相关文章

  1. HDU 3839 Ancient Messages(DFS)

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

  2. hdu 3839 Ancient Messages (dfs )

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

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

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

  4. HDOJ(HDU).2660 Accepted Necklace (DFS)

    HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...

  5. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

  6. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  7. HDOJ(HDU).1035 Robot Motion (DFS)

    HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...

  8. HDU 1501 Zipper 【DFS+剪枝】

    HDU 1501 Zipper [DFS+剪枝] Problem Description Given three strings, you are to determine whether the t ...

  9. HDU 1401 Solitaire 双向DFS

    HDU 1401 Solitaire 双向DFS 题意 给定一个\(8*8\)的棋盘,棋盘上有4个棋子.每一步操作可以把任意一个棋子移动到它周围四个方向上的空格子上,或者可以跳过它四个方向上的棋子(就 ...

  10. ACM: HDU 2563 统计问题-DFS+打表

    HDU 2563 统计问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u HDU 2 ...

随机推荐

  1. 【53.57%】【codeforces 722D】Generating Sets

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. Boost.Asio c++ 网络编程翻译(10)

    read/write方法 这些方法对一个流进行读写操作(能够是套接字,或者其它表现的像流的类): async_read(stream, buffer [, completion],handler):这 ...

  3. Unity3D资源管理架构

    在Unity3D引擎中,场景资源文件(.unity)是以2进制格式存储的.但同一时候它也有一种基于文本的表现格式. 可在Edit>Project Setting>Editor 中设置: 1 ...

  4. php实现表示数值的字符串(is_numeric($s))

    php实现表示数值的字符串(is_numeric($s)) 一.总结 is_numeric($s) 二.php实现表示数值的字符串 题目描述 请实现一个函数用来判断字符串是否表示数值(包括整数和小数) ...

  5. Codeforces 491B. New York Hotel 最远曼哈顿距离

    最远曼哈顿距离有两个性质: 1: 对每一个点(x,y)  分别计算  +x+y , -x+y , x-y , -x-y 然后统计每种组合的最大值就能够了, 不会对结果产生影响 2: 去掉绝对值 , 设 ...

  6. 学汇编的时候可以拿IDA之类的反汇编工具辅助学习,再用gdb或者IDA动态调试,跟踪每条指令的 执行结果。都不难

    作者:潘安仁链接:https://www.zhihu.com/question/40720890/answer/87926792来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  7. MySQL 备份错误日志

    MySQL 备份错误日志:   shell> mv host_name.err host_name.err-old shell> mysqladmin -u root -p flush-l ...

  8. Mina框架项目运用

    近期最一个项目对通信要求比較严格,须要建立长连接,且能处理多并发,所以选择了Mina框架.以下就简单记录开发的过程吧: mina 开发须要的jar包: mina pc端通信: 服务端: package ...

  9. 一个封装比较完整的FTP类——clsFTP

    前几天,看见园子里面的博友写了一个支持断点续传的FTP类,一时技痒,干脆写了个更完整的clsFtp类.只是我写这个clsFtp不是支持断点续传的目的,而是为了封装FTP几个基本常用的操作接口. 功能 ...

  10. 理解Erlang/OTP - Application

    http://www.cnblogs.com/me-sa/archive/2011/12/27/erlang0025.html 1>application:start(log4erl). 我们就 ...