UVA - 1103Ancient Messages

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.
Figure C.1: Six hieroglyphs
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.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.
Figure C.2: AKW Figure C.3: AAAAA
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
000000000000000000000000000000000000

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

题解:傻不拉唧的自己,倒腾了测试数据还以为自己的代码错了呐,倒腾数据弄了半天,最终发现原来是没删了freopen("data.in","r",stdin);

我哩个无语啊。。。。

题意是让升序输出象形文字代表的字母,可以根据里面圆的个数判断;

测试数据:

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

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#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[MAXN][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>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",&w,&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<h;j++){
for(k=0;k<16;k++)
if(s[j]==ch[k]){
for(int x=0;x<4;x++)
mp[i][l++]=p[k][x];
break;
}
}
}
dfs(0,0);
k=0;
for(int i=0;i<=w;i++)
for(int j=0;j<4*h;j++){
if(mp[i][j]==1){
cnt=0;
dfs2(i,j);
ans[k++]=an[cnt];
}
}
sort(ans,ans+k,cmp);
printf("Case %d: ",++kase);
for(int i=0;i<k;i++)printf("%c",ans[i]);
puts("");
}
return 0;
}

  

UVA - 1103Ancient Messages(dfs)的更多相关文章

  1. UVA - 11853 Paintball(dfs)

    UVA - 11853 思路:dfs,从最上面超过上边界的圆开始搜索,看能不能搜到最下面超过下边界的圆. 代码: #include<bits/stdc++.h> using namespa ...

  2. HDU 3839 Ancient Messages(DFS)

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

  3. UVA 1267 Network(DFS)

    题目链接:https://vjudge.net/problem/UVA-1267 首先我们要把这样一棵无根树转换成有根树,那么树根我们可以直接使用$VOD$. 还有一个性质:如果深度为$d$的一个节点 ...

  4. hdu 3839 Ancient Messages (dfs )

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

  5. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

  6. LeetCode Subsets (DFS)

    题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...

  7. uva 725 Division(除法)暴力法!

    uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  8. HDU 2553 N皇后问题(dfs)

    N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 在 ...

  9. 深搜(DFS)广搜(BFS)详解

    图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...

随机推荐

  1. jQuery treeview的简单用法

    最近的项目要用到treeview插件,刚好就自己整理一下这方面的资料. 1.文档树示例 最简单的一个例子就是文档树的实现.效果如下图所示. 在使用treeview之前,html文档中需要包含几个jqu ...

  2. 织梦list文章列表按权重排序

    织梦的文章列表按权重排序 DEDECMS(织梦)5.6系统支持文档权重weight排序,可以在模板中使用: {dede:arclist row='10' titlelen='50' orderby=' ...

  3. 翻译 GITHUB上HOW TO BE A GOOD PROGRAMMER

    转载请注明出处: http://www.cnblogs.com/hellocwh/p/5184072.html 更多内容点击查看 https://ahangchen.gitbooks.io/windy ...

  4. 几种改变Activity回退栈默认行为的Intent Flag

    FLAG_与LaunchMode相比最大的不同是临时性 1.FLAG_ACTIVITY_NEW_TASK: Developer.android.com的说法: (1)在新的task中启动这个Activ ...

  5. sql like 通配符 模糊查询技巧及特殊字符

    最近碰到like模糊匹配的问题,找到一些答案接触迷惑,觉得有知识是自己忽略的,现在整理出来,既强化记忆,又是一次记录,以下转自一篇Blog,关于sql server like的通配符和字符带通配符的处 ...

  6. CSharp tar类型文件压缩与解压

    最近闲暇时间开始写点通用基础类在写到tar类型文件压缩与解压时遇到点问题 压缩用的类库我是下载的 SharpZipLib_0860版本 先上代码 加压核心 /// <summary> // ...

  7. NOI2011 Day2

    NOI2011 Day2 道路修建 题目描述:给出一棵树,求每条边的两边的端点数的差乘边权之和. solution: 题目可能描述得不太清楚,如图: 对于虚边,如果边权为10,两边的端点数之差为2,这 ...

  8. [LeetCode][Python]Integer to Roman

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/integer ...

  9. HDU 3046 Pleasant sheep and big big wolf(最小割)

    HDU 3046 Pleasant sheep and big big wolf 题目链接 题意:一个n * m平面上,1是羊.2是狼,问最少要多少围墙才干把狼所有围住,每有到达羊的路径 思路:有羊和 ...

  10. CSS定位深入理解 完全掌握CSS定位 相对定位和绝对定位

    其实前面的标准流和浮动流都很理解,就是定位不太好理解,特别是相对定位和绝对定位,很多刚开始学的同学不好区分.因此这里,小强老师和大家一起分享CSS定位的学习. 通过我们前面的学习,我们网页布局方法: ...