Uva-1103ancient Messages (DFS)

Source: Internet
Author: User

Uva-1103ancient Messages

In order to understand early civilizations, archaeologists often study texts written in ancient languages.
One such language, used in Egypt + than, years ago, is based on characters called Hieroglyphs.
Figure C.1 shows six hieroglyphs and their names. In this problem, you'll write a program to recognize
These six characters.
Figure C.1:six Hieroglyphs
Input
The input consists of several test cases, each of which describes a 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 both white pixels, and so on) would is represented in
Hexadecimal notation as 9c. Only digits and lowercase letters A through f is used in the hexadecimal
Encoding. The first line of all test case contains-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 was part of a valid hieroglyph.
Each hieroglyph consists of a connected set of black pixels and each black pixel have at least one
Other black pixel in its top, bottom, left, or right side.
the hieroglyphs do not touch and no hieroglyph are inside another hieroglyph.
two black pixels that touch diagonally would always has a common touching black pixel.
the hieroglyphs are distorted but each have a shape that's topologically equivalent to one of
The symbols in Figure C.1. (Figures is topologically equivalent if each can is transformed
Into the other by stretching without tearing.)
The last test was followed by a line containing the zeros.
Output
For each test case, the 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 is shown on the page.
Figure C.2:akw Figure C.3:aaaaa
Sample Input
100 25
0000000000000000000000000
0000000000000000000000000
... (lines omitted) ...
00001fe0000000000007c0000
00003fe0000000000007c0000
... (lines omitted) ...
0000000000000000000000000
0000000000000000000000000
150 38
00000000000000000000000000000000000000
00000000000000000000000000000000000000
... (lines omitted) ...
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
... (lines omitted) ...
00000000000000000000000000000000000000
000000000000000000000000000000000000

00000000000000000000000000000000000000
0 0
Sample Output
Case 1:akw
Case 2:AAAAA

The puzzle: Silly pull of their own, Daoteng the test data also thought their code wrong, Daoteng data get a half-day, finally found that the original is not deleted freopen ("Data.in", "R", stdin);

I have no words ....

Test instructions is to let the output of glyphs in ascending order of letters, can be judged according to the number of circles inside;

Test data:

http://demo.netfoucs.com/u013451221/article/details/38179321

Code:

#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include < algorithm>using namespace std; #define MEM (x, y) memset (x,y,sizeof (×)) #define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define P_ printf ("") const int inf=0x3f3f3f3f;typedef long Long ll;const int maxn=1010;int w,h,cnt;int mp[m Axn][maxn];char ans[maxn];char s[maxn];char an[6]={' W ', ' A ', ' K ', ' J ', ' s ', ' D '};char ch[]={' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ' , ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' d ', ' e ', ' F '};int disx[8]={0,0,1,-1,1,1,-1,-1};int disy[8]={1,-1,0,0,-1,1,-1,1};int p[16] [4]={{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1}, {0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1}, {1,0,0,0},{1,0,0,1},{ 1,0,1,0},{1,0,1,1}, {1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}};void dfs (int x,int y) {if (x<0| | y<0| | x>w+1| | y>4*h+1) return;if (Mp[x][y]) return;mp[x][y]=-1;for (int i=0;i<8;i++) DFS (X+disx[i],y+disy[i]);} void dfs2 (int x,int y) {if (x<0| | y<0| | x>w| | Y&GT;4*H) return;if (mp[x][y]==-1) return;if (mp[x][y]==0) {DFS (x, y); cnt++;return;} mp[x][y]=-1;for (int i=0;i<8;i++) DFS2 (X+disx[i],y+disy[i]);} int cmp (char A,char b) {return a<b;} int main () {int k,l,kase=0;//freopen ("data.in", "R", stdin),//freopen ("Data.out", "w", stdout), while (scanf ("%d%d", &AMP;W,&AMP;H), w|h) {mem (mp,0), mem (ans,0), for (int i=1;i<=w;i++) {scanf ("%s", s), L=1;int Len=strlen (s); for (int j=0 ; j

  

Uva-1103ancient Messages (DFS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.