题目链接:Ancient Messages HDU - 3839

===================================================

Ancient Messages

Time Limit: 1000 ms
Memory Limit: 32768 kB

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

===================================================

题意:就是给你一副图,图里面有很多埃及象形字,然后图像由像素0,1构成,1表示颜色黑,0则表示白。

算法:BFS

难点:

  • 第一点在于怎么巧妙区别埃及象形字? 每个埃及象形字都是有闭合空间并且数量对于每个埃及象形字不同,所以可以从空白入手。
  • 第二点在于如何区分埃及象形字内的空白与外空白? 这里题目给出了关键点,就是每两个埃及象形字必不连接且不嵌套。并且黑色部分永远相连不断。

思路:

  • 预处理:这里使用十六进制代表二进制像素,所以需要还原。
  • 第一步:从边界开始读空白,进行白色BFS,把所有埃及象形字的外空白标记。
  • 第二步:从上到下从左到右,找埃及象形字,遇到则开始黑色BFS,每遇到白色没标记则开始白色BFS标记;重点记录,遇到几次空白,即这个埃及象形字有多少闭合空白空间。从而区分这个是什么埃及象形字;
  • 第三步:通过BFS得出的埃及象形字数量,然后字典输出即可AC。

===================================================

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>using namespace std;int n,m,ditu[202][202],ans[8],cas=1;int gg[] = {1,5,3,2,4,0};
char gk[] = {'A','D','J','K','S','W'};int xx[] = {1,-1,0,0};
int yy[] = {0,0,1,-1};bool vis[202][202];struct node{int x,y;node(int a,int b):x(a),y(b) {};
};void bfs_white(int a,int b){queue<node> q;q.push(node(a,b)),vis[a][b] = true;while(!q.empty()){node p = q.front();q.pop();for(int i=0;i<4;i++){int x = p.x + xx[i],y = p.y + yy[i];if(x<0||x>=n||y<0||y>=m||ditu[x][y]||vis[x][y]) continue;q.push(node(x,y)),vis[x][y] = true;}}return ;
}void bfs_black(int a,int b){queue<node> q;int acer = 0;q.push(node(a,b)),vis[a][b] = true;while(!q.empty()){node p = q.front();q.pop();for(int i=0;i<4;i++){int x = p.x + xx[i],y = p.y + yy[i];if(x<0||x>=n||y<0||y>=m||vis[x][y]) continue;if(ditu[x][y]) q.push(node(x,y)),vis[x][y] = true;else bfs_white(x,y),acer++;}}ans[acer]++;return ;
}void show(){for(int i=0;i<n;i++){for(int j=0;j<m;j++) cout<<ditu[i][j]<<" ";cout<<endl;}
}int main()
{while(~scanf("%d%d",&n,&m)){if(!n&&!m) break;for(int i=0;i<n;i++) for(int j=0,z=0;j<m;j++){char ch = getchar();while(ch==' '||ch=='\n') ch = getchar();int num;if(ch>='a'&&ch<='z') num = ch-'a'+10;else num = ch-'0';if(num>=8) ditu[i][z++] = 1,num-=8;else ditu[i][z++] = 0;if(num>=4) ditu[i][z++] = 1,num-=4;else ditu[i][z++] = 0;if(num>=2) ditu[i][z++] = 1,num-=2;else ditu[i][z++] = 0;if(num>=1) ditu[i][z++] = 1;else ditu[i][z++] = 0;}m*=4;//show();memset(ans,0,sizeof ans);memset(vis,false,sizeof vis);//边界找0for(int j=0;j<m;j++){if(!vis[0][j]&&ditu[0][j]==0) bfs_white(0,j);if(!vis[n-1][j]&&ditu[n-1][j]==0) bfs_white(n-1,j);}for(int i=0;i<n;i++){if(!vis[i][0]&&ditu[i][0]==0) bfs_white(i,0);if(!vis[i][m-1]&&ditu[i][m-1]==0) bfs_white(i,m-1);}//找图像for(int i=0;i<n;i++)for(int j=0;j<m;j++) if(!vis[i][j]&&ditu[i][j]) bfs_black(i,j);printf("Case %d: ",cas++);for(int i=0;i<6;i++) for(int j=0;j<ans[gg[i]];j++) printf("%c",gk[i]);puts("");}return 0;
}

Ancient Messages HDU - 3839相关推荐

  1. UVA - 1103:Ancient Messages

    Ancient Messages 来源:UVA 标签: 参考资料: 相似题目: 题目 In order to understand early civilizations, archaeologist ...

  2. UVA1103 古代象形符号 Ancient Messages解题报告(DFS,字符串)难度⭐⭐⭐⭐

    题目翻译 为了识别3000年前古埃及用到的6种象形文字.每组数据包含一个H行W列的字符矩阵(H≤200,W≤50 ),每个字符为4个相邻像素点的十六进制(例如,10011100对应的字符就是9c).转 ...

  3. Uva 1103 Ancient Messages

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

  4. Ancient Messages UVA - 1103

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

  5. UVA 1103 - Ancient Messages(古代象形符号) By SuCicada

    本题的目的是识别3000年前古埃及用到的6种象形文字,如图6-10所示. 图6-10 古代象形符号 每组数据包含一个H行W列的字符矩阵(H≤200,W≤50),每个字符为4个相邻像素点的 十六进制(例 ...

  6. 例题6-13 古代象形符号(Ancient Messages,World Finals 2011,UVa 1103)

    原题链接:https://vjudge.net/problem/UVA-1103 分类:图 备注:思维 前言:说实话我确实自己写不出,写下面代码的时候对一下uDebug,不过我没有看作者代码了(早就看 ...

  7. 古代象形符号,Ancient Messages,UVA1103

    题目链接:https://vjudge.net/problem/UVA-1103 题解:通过观察题目,所给的几个象形符号可以由每个图像所包围产生的洞洞来确定,统计dfs对图中的块进行染色,然后再统计每 ...

  8. UVA1103 古代象形符号 Ancient Messages

    首先是理解题意,这个刘汝佳写的很明白了,其实就是找1里面包着的有多少个0的连通块,不同的1的块互不干扰不相邻不包含,然后我就看uva上的例子,想把16进制化成2进制然后看是不是对的上,结果硬是对不上号 ...

  9. (UVA 1103) Ancient Meesages(DFS连通分量计数+种子填充floodfill算法)

    原题: UVA 1103 洛谷 古代象形符号 问题描述 问题输入输出 输入 输出 输入输出样例 Input: 6 2 00 7c 44 7c 30 00 6 25 000000000000000000 ...

最新文章

  1. cocos creator 安卓原生平台环境_竞技对抗小游戏单挑篮球开发历程 | Cocos技术派第12期...
  2. JDK之jstat的用法
  3. 配置Eureka高可用
  4. tokudb mysql_【MySQL】TokuDB引擎安装教程
  5. 鸿蒙系统支持980,鸿蒙手机上线时间 鸿蒙系统支持哪些手机2021最新汇总
  6. 【多元域乘法】多项式乘法电路原理及MATLAB详解
  7. [JS] 001_JavaScript基础增强
  8. HTTP 的概念、原理、工作机制、数据格式和REST(HenCoder学习总结,待整理中...)
  9. 点餐系统小程序源码|小程序点餐系统
  10. 用友服务器换了ip地址怎么修改,用友服务器ip地址更换
  11. 芝诺数解|【三】前程未可量,奋发而为之——国产动画电影探索之路
  12. Win10重复按键盘经常按不出?Win10关闭筛选键步骤
  13. 【2019.05】JS逆向——破解百度翻译参数(sign)爬虫 超级详细
  14. STM32串口屏应用
  15. vue + elment ui打印表格数据
  16. html: a标签中的href的作用
  17. 哈工大计算机系统大作业
  18. qemu 规范路径_EVE-NG镜像添加技巧(以思科虚拟化产品为例)
  19. 修仙第一步:凌晨打坐
  20. python sql_pandasql:让python讲SQL

热门文章

  1. python pandas 分割DataFrame中的字符串及元组
  2. 【FatFs】手动移植FatFs,将SRAM虚拟U盘
  3. UltraEdit常见问题及解决教程
  4. 041_CSS及案例-网站主页模板
  5. 怕你不信,100行极简原生html现实3D雪花飘飘动效
  6. 6-7 使用函数求素数和 (20 分)
  7. 诚之和:SQL Where – 子句示例
  8. 【网络流】基础二分图的最大匹配问题
  9. 【Unity】Unity实现鼠标控制摄像机围绕物体旋转镜头 滑轮控制远近
  10. 股票分析及利用tushare查看股票部分信息