UVA 1103
来源:互联网 发布:飞秋for mac 下载 编辑:程序博客网 时间:2024/04/30 15:28
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 pixels10011100 (one black pixel, followed by two white pixels, and so on) would be represented in hexadecimal notation as9c. 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 < H200) is the number of scan lines in the image.W(0 < W50) 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.1. (Two figures are topologically equivalent if each can be transformed into the other by stretching without tearing.)
The last test case is followed by a line containing two zeros.
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 2500000000000000000000000000000000000000000000000000...(50 lines omitted)...00001fe0000000000007c000000003fe0000000000007c0000...(44 lines omitted)...00000000000000000000000000000000000000000000000000150 380000000000000000000000000000000000000000000000000000000000000000000000000000...(75 lines omitted)...0000000003fffffffffffffffff000000000000000000003fffffffffffffffff00000000000...(69 lines omitted)...00000000000000000000000000000000000000000000000000000000000000000000000000000 0
Sample Output
Case 1: AKWCase 2: AAAAA
#include <iostream>#include<cstring>#include<cstring>#include<cstdio>#include<vector>#include<set>#include<algorithm>using namespace std;const int mx=280;int n,m,mp[mx][mx],g[mx][mx],num,used[mx][mx];char ch_num[10]="WAKJSD";int dx[]={0,0,1,-1},dy[]={1,-1,0,0},a[1000000];void dfs(int x,int y){ g[x][y]=num; for(int i=0;i<4;i++) { int nx=x+dx[i],ny=y+dy[i]; if(nx>=0&&nx<n&&ny>=0&&ny<m&&mp[nx][ny]==1) { if(g[nx][ny]==0) dfs(nx,ny); } }}int dfs0(int x,int y){ used[x][y]=true; vector<int> gg; for(int i=0;i<4;i++) { int nx=x+dx[i],ny=y+dy[i]; if(nx>=0&&nx<n&&ny>=0&&ny<m) { if(!used[nx][ny]) { if(g[nx][ny]) gg.push_back(g[nx][ny]); if(g[nx][ny]==0) { int t=dfs0(nx,ny); if(t) gg.push_back(t); } } } } for(int i=0;i<gg.size();i++) { if(gg[i]!=gg[0]) return -1; if(gg[i]==-1) return -1; } if(gg.size()>=1) return gg[0]; return 0;}int main(){ int Cases=0; while(scanf("%d%d",&n,&m),n||m) { memset(mp,0,sizeof(mp)); for(int i=2;i<n+2;i++) { for(int j=2;j<m+2;j++) { int t; scanf("%1x",&t); mp[i][j*4]=t/8; mp[i][j*4+1]=t%8/4; mp[i][j*4+2]=t%4/2; mp[i][j*4+3]=t%2; } } n+=10;m+=4; num=1;m*=4; memset(g,0,sizeof(g));memset(used,0,sizeof(used)); memset(a,0,sizeof(a)); for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(mp[i][j]==1&&g[i][j]==0) {dfs(i,j);num++;} for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(mp[i][j]==0&&!used[i][j]) { int tt=dfs0(i,j); if(tt!=-1) a[tt]++; } vector<char> ans; if(num>2) { for(int i=1;i<num;i++) ans.push_back(ch_num[a[i]]); } else if(num==2) { ans.push_back(ch_num[a[1]-1]); } sort(ans.begin(),ans.end()); printf("Case %d: ",++Cases); for(int i=0;i<ans.size();i++) printf("%c",ans[i]); printf("\n"); } return 0;}水题,但是要注意边界的情况
- uva 1103
- UVA 1103
- UVA 1103
- UVA 1103
- UVa 1103
- UVA-1103- Ancient Messages
- Uva - 1103 - Ancient Messages
- uva 1103 详解
- uva 1103 dfs
- uva 1103 Ancient Messages
- UVA 1103 象形符号
- UVA 1103 Ancient Messages
- UVA-1103 Ancient Messages
- uva
- UVA
- UVA
- UVA
- uva
- 降低图片的内存消耗
- 婚姻是爱情的坟墓,却又是爱情最好的归宿
- Factstone Benchmark
- 基于MFC的串口通信
- Android egl和opengl
- UVA 1103
- 开源应用架构之asterisk
- POJ 2513 Colored Sticks(字典树+并查集+欧拉回路)
- hihoCoder 1082 然而沼跃鱼早就看穿了一切
- zoj 2016 poj 1386 Play on Words 欧拉回路+DFS
- Java删除ArrayList中的重复元素的2种方法
- Binary Tree Inorder Traversal
- easyui toolbar 动态显示与隐藏
- 南阳OJ~~AS||码排序