非常有趣的一道题目,大意是给你六种符号的16进制文本,让你转化成二进制并识别出来

代码实现上参考了//http://blog.csdn.net/u012139398/article/details/39533409

#include<cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set> using namespace std; const int MAXH = ;
const int MAXW = ;
int H,W;
int dx[] = {, , -, };
int dy[] = {, -, , };
char* bin[]= {"","","","","","","",""
,"","","","","","","",""};
char code[] = "WAKJSD"; char pic1[MAXH][MAXW];
char pic[MAXH][MAXW<<];
int color[MAXH][MAXW<<]; void dfs(int x,int y,int col)
{
color[x][y] = col;
for(int i = ; i < ; ++i){
int nx = x + dx[i], ny = y + dy[i];
if(nx >= && nx < H && ny >= && ny < W
&& pic[x][y] == pic[nx][ny] && !color[nx][ny])
dfs(nx,ny,col);
}
}
int main()
{
// freopen("in.txt","r",stdin);// FE
int cas = ;
while(scanf("%d%d",&H,&W),H){ memset(pic,,sizeof(pic));
memset(color,,sizeof(color)); for(int i = ; i < H; ++i)
scanf("%s",pic1[i]);
for(int i = ; i < H; ++i)
for(int j = ; j < W; ++j){
if(pic1[i][j]<=''&&''<=pic1[i][j])
pic1[i][j] -= '';
else
pic1[i][j] -= 'a' - ;
for(int k = ; k < ; ++k){//decode
pic[i+][+(j<<)+k] = bin[pic1[i][j]][k] - '';
}
} H += ;
W = (W<<)+;
vector<int> cc;
int cnt = ;//cnt = 1一定是白色背景
for(int i = ; i < H; ++i)
for(int j = ; j < W; ++j){
if(!color[i][j]) {
dfs(i,j,++cnt);
if(pic[i][j] == ) cc.push_back(cnt);//记录黑色所在的连通块 //!!没放到括号里
} } vector< set<int> > neigh(cnt+);
for(int i = ; i < H; ++i)
for(int j = ; j < W; ++j) {
if(pic[i][j]){
for(int k = ; k < ; ++k){
int x = i + dx[k], y = j + dy[k];
if(x >= && x < H && y >= && y < W
&& pic[x][y] == && color[x][y] != )
neigh[color[i][j]].insert(color[x][y]);
}
}
} vector<char> ans;
for(int i = ; i < cc.size(); ++i)
ans.push_back(code[neigh[cc[i]].size()]);
sort(ans.begin(),ans.end()); printf("Case %d: ",++cas);
for(int i = , sz = ans.size(); i < sz; ++i)
printf("%c",ans[i]);
puts("");
}
return ;
}

[uva]AncientMessages象形文字识别 (dfs求连通块)的更多相关文章

  1. UVa 572 油田(DFS求连通块)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVA 572 Oil Deposits油田(DFS求连通块)

    UVA 572     DFS(floodfill)  用DFS求连通块 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format: ...

  3. UVA 572 -- Oil Deposits(DFS求连通块+种子填充算法)

    UVA 572 -- Oil Deposits(DFS求连通块) 图也有DFS和BFS遍历,由于DFS更好写,所以一般用DFS寻找连通块. 下述代码用一个二重循环来找到当前格子的相邻8个格子,也可用常 ...

  4. DFS入门之二---DFS求连通块

    用DFS求连通块也是比较典型的问题, 求多维数组连通块的过程也称为--“种子填充”. 我们给每次遍历过的连通块加上编号, 这样就可以避免一个格子访问多次.比较典型的问题是”八连块问题“.即任意两格子所 ...

  5. [C++]油田(Oil Deposits)-用DFS求连通块

    [本博文非博主原创,均摘自:刘汝佳<算法竞赛入门经典>(第2版) 6.4 图] [程序代码根据书中思路,非独立实现] 例题6-12 油田(Oil Deposits,UVa572) 输入一个 ...

  6. HDU1241 Oil Deposits —— DFS求连通块

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...

  7. 图-用DFS求连通块- UVa 1103和用BFS求最短路-UVa816。

    这道题目甚长, 代码也是甚长, 但是思路却不是太难.然而有好多代码实现的细节, 确是十分的巧妙. 对代码阅读能力, 代码理解能力, 代码实现能力, 代码实现技巧, DFS方法都大有裨益, 敬请有兴趣者 ...

  8. UVA 572 dfs求连通块

    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...

  9. 用DFS求连通块(种子填充)

    [问题] 输入一个m行n列的字符矩阵,统计字符“@”组成多少个八连块.如果两个字符“@”所在的格子相邻(横.竖或者对角线方向),就说它们属于同一个八连块.例如,图6-9中有两个八连块. 图6-9 [分 ...

随机推荐

  1. Spring入门第七课

    Bean之间的关系:继承和依赖. 继承Bean配置 Spring允许继承bean的配置,被继承的bean称为父bean,继承这个父bean的Bean称为子Bean. 子Bean从父Bean中继承配置, ...

  2. es6常用方法

    一.let 和 constlet 声明变量,只在所在的块区有效,不存在变量提升:var 存在变 量提升const 声明常量,只在所在块区有效 二.变量的解构赋值1.数组的解构赋值let [a, b, ...

  3. 下拉刷新,上拉加载功能--dropload.js的使用

    这段时间工作太忙了,没时间更新博客内容,在这段时间,也学习到了不少新的知识.今天先整理一下dropload.js的使用方法吧,这个是在为项目中使用过的插件,很好用,但是真正用到项目中还是会有一些小小的 ...

  4. linux grep (转)

    常用用法 [root@www ~]# grep [-acinv] [--color=auto] '搜寻字符串' filename 选项与参数: -a :将 binary 文件以 text 文件的方式搜 ...

  5. JPA @MappedSuperclass注解的使用说明(转)

    (2011-11-07 11:37:30) 转载▼ http://blog.sina.com.cn/s/blog_7085382f0100uk4p.html 标签: 杂谈   基于代码复用和模型分离的 ...

  6. js中的面向对象程序设计

    面向对象的语言有一个标志,即拥有类的概念,抽象实例对象的公共属性与方法,基于类可以创建任意多个实例对象,一般具有封装.继承.多态的特性!但JS中对象与纯面向对象语言中的对象是不同的,ECMA标准定义J ...

  7. discuz 3.x ssrf分析

    discuz 3.x版本ssrf漏洞分析 漏洞促发点\souce\module\forum\forum_ajax.php 最后看到了这里 ***$_GET['action']='downremotei ...

  8. G.Longest Palindrome Substring

    链接:https://ac.nowcoder.com/acm/contest/908/G 题意: A palindrome is a symmetrical string, that is, a st ...

  9. Codeforces Round #561 (Div. 2) C. A Tale of Two Lands

    链接:https://codeforces.com/contest/1166/problem/C 题意: The legend of the foundation of Vectorland talk ...

  10. hdu5884

    #include <cstdio> #include <queue> #include <algorithm> #include <string.h> ...