非常有趣的一道题目,大意是给你六种符号的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. C++类型起别名的方式

    C++给类型起别名的方式: #include <iostream> using namespace std; #define DString std::string //! 不建议使用!t ...

  2. Debian系统下的ftp服务搭建

    安装vsftpd服务 $ sudo apt install vsftpd 配置参数 命令输入 $ vim /etc/vsftpd.conf 使用如下配置 # Example config file / ...

  3. MS SQL Server的LTRIM,RTRIM和TRIM函数

    在MS SQL Server 2017有了一个新函数TRIM,整合以前版本LTRIM和RTRIM. 这几个函数都是去除字符串头部后尾部的空格. DECLARE @str NVARCHAR(MAX) = ...

  4. 大白话5分钟带你走进人工智能-第二十六节决策树系列之Cart回归树及其参数(5)

                                                    第二十六节决策树系列之Cart回归树及其参数(5) 上一节我们讲了不同的决策树对应的计算纯度的计算方法, ...

  5. Keras实现MNIST分类

      仅仅为了学习Keras的使用,使用一个四层的全连接网络对MNIST数据集进行分类,网络模型各层结点数为:784: 256: 128 : 10:   使用整体数据集的75%作为训练集,25%作为测试 ...

  6. Animation Starter Pack中动画蓝图事件添加的位置

    可以直接在动画状态机的详情页添加简单事件,跟在动画里添加的通知事件效果一致

  7. codeforces 352D - Jeff and Furik【期望dp】

    首先恋人操作过一轮之后逆序对不会变多,所以设f[i]为把i个逆序对消掉的期望次数,f[i]=0.5f[i-2]+0.5f[i]+2,化简然后递推即可 #include<iostream> ...

  8. python 合并两个文件并将合并内容保存在另一个文件中

    简单地文件合并方法 思路如下: 分别读取两个文件中的内容,并将其保存在一个列表中,将列表通过join()函数转为字符,并将新字符保存在新的文件中. 其中,test1.txt中的内容为: test2.t ...

  9. python进阶08 MySQL基础补充

    python进阶08 MySQL基础补充 本次课程都是基于三张表格的使用 一.子查询 #如何找到‘张三’的成绩 #思路:先找到张三的学号,在拿这个张三的学号到成绩表里面去匹配,得出成绩 #如何用一条查 ...

  10. Codeforces Round #566 (Div. 2) A. Filling Shapes

    链接: https://codeforces.com/contest/1182/problem/A 题意: You have a given integer n. Find the number of ...