Uva1103 Ancient Messages
题意:识别图中的象形文字。但是,图形可以任意的拉伸,但不能拉断。
分析:这种题如果图形没有特征是不可做类型的题,不过观察图形可以发现每个图形中的洞的数量是一定的,我们只需要数出每一个封闭图形的洞数就能知道这是哪个图形.
虽然知道了原理,但是并不是特别好做,首先我们需要一次dfs将所有图形旁边的点全都变为“不可访问”,然后从每个黑点开始枚举,向四周扩展,遇到白色的块就用第一次的dfs函数覆盖,否则继续第二次dfs,两次dfs交错使用,思路比较巧妙.
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- //0表示空白位置,-1表示不能访问了.
- const int maxn = ;
- int n, m,kase,a[maxn][maxn],flag[maxn][maxn],cnt,num[maxn];
- char s16[] = { '', '', '', '', '', '', '', '', '', '', 'a', 'b', 'c', 'd', 'e', 'f' };
- char fuhao[] = { 'A', 'D', 'J', 'K', 'S', 'W' };
- int s2[][] =
- {
- { , , , }, { , , , }, { , , , }, { , , , },
- { , , , }, { , , , }, { , , , }, { , , , },
- { , , , }, { , , , }, { , , , }, { , , , },
- { , , , }, { , , , }, { , , , }, { , , , }
- };
- void dfs1(int x,int y)
- {
- if (x < || x > n + || y < || y > m + || a[x][y] != )
- return;
- a[x][y] = -;
- dfs1(x - , y);
- dfs1(x + , y);
- dfs1(x, y - );
- dfs1(x, y + );
- }
- void dfs2(int x, int y)
- {
- if (x < || x > n + || y < || y > m + || a[x][y] == -)
- return;
- if (a[x][y] == )
- {
- cnt++;
- dfs1(x, y);
- return;
- }
- a[x][y] = -;
- dfs2(x - , y);
- dfs2(x + , y);
- dfs2(x, y - );
- dfs2(x, y + );
- }
- int main()
- {
- while (scanf("%d%d", &n, &m) == && (n || m))
- {
- memset(a, , sizeof(a));
- memset(num, , sizeof(num));
- for (int i = ; i <= n; i++)
- {
- getchar();
- char ch;
- int tot = ;
- for (int j = ; j <= m; j++)
- {
- scanf("%c", &ch);
- for (int k = ; k < ; k++)
- {
- if (ch == s16[k])
- {
- for (int l = ; l < ; l++)
- a[i][++tot] = s2[k][l];
- break;
- }
- }
- }
- }
- m *= ;
- dfs1(, );
- for (int i = ; i < n; i++)
- for (int j = ; j < m; j++)
- if (a[i][j] == )
- {
- cnt = ;
- dfs2(i, j);
- if (cnt == )
- num[]++;
- if (cnt == )
- num[]++;
- if (cnt == )
- num[]++;
- if (cnt == )
- num[]++;
- if (cnt == )
- num[]++;
- if (cnt == )
- num[]++;
- }
- printf("Case %d: ", ++kase);
- for (int i = ; i <= ; i++)
- {
- while (num[i]--)
- printf("%c", fuhao[i]);
- }
- printf("\n");
- }
- return ;
- }
Uva1103 Ancient Messages的更多相关文章
- K - Ancient Messages(dfs求联通块)
K - Ancient Messages Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Subm ...
- UVA1103 古代象形符号 Ancient Messages 题解
题目链接: https://www.luogu.org/problemnew/show/UVA1103 题目分析: 我们可以先进行矩阵的还原 for(int k=1;k<=4;k++) { a[ ...
- UVa 1103 Ancient Messages(二重深搜)
In order to understand early civilizations, archaeologists often study texts written in ancient lang ...
- Ancient Messages UVA - 1103
题目链接:https://vjudge.net/problem/UVA-1103 题目大意:每组数据包含H行W列的字符矩阵(H<=200,W<=50) 每个字符为为16进制 你需要把它转 ...
- HDU 3839 Ancient Messages(DFS)
In order to understand early civilizations, archaeologists often study texts written in ancient lang ...
- hdu 3839 Ancient Messages (dfs )
题目大意:给出一幅画,找出里面的象形文字. 要你翻译这幅画,把象形文字按字典序输出. 思路:象形文字有一些特点,分别有0个圈.1个圈.2个圈...5个圈.然后dfs或者bfs,就像油井问题一样,找出在 ...
- UVa 1103 (利用连通块来判断字符) Ancient Messages
本题就是灵活运用DFS来求连通块来求解的. 题意: 给出一幅黑白图像,每行相邻的四个点压缩成一个十六进制的字符.然后还有题中图示的6中古老的字符,按字母表顺序输出这些字符的标号. 分析: 首先图像是被 ...
- Uva 1103 Ancient Messages
大致思路是DFS: 1. 每个图案所包含的白色连通块数量不一: Ankh : 1 ; Wedjat : 3 ; Djed : 5 ; Scarab : 4 ; Was : 0 ; Ak ...
- 【例题 6-13 UVA - 1103】Ancient Messages
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每个图案里面的"洞"的个数都是不同的. 则可以根据这个判别每个图像是什么. 先用dfs确定轮廓之后. 再从每个白 ...
随机推荐
- 洛谷 P2142 高精度减法(模板)
题目描述 高精度减法 输入输出格式 输入格式: 两个整数a,b(第二个可能比第一个大) 输出格式: 结果(是负数要输出负号) 输入输出样例 输入样例#1: 2 1 输出样例#1: 1 说明 20%数据 ...
- laravel 模型 $table $guarded $hidden
首先以App\User模型为例 1.$table属性 表名,对应数据库中的表名 2.guarded)属性 guarded表示在create()方法中不能被赋值的字段 3.$hidden属性 $hid ...
- 三分 POJ 2420 A Star not a Tree?
题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...
- Cesium加载影像
注意:使用自定义数据源时,Cesium.Viewer类参数必须设置为 baseLayerPicker:false A. 使用天地图数据源 //天地图var provider=new Cesium.We ...
- Spring Boot (28) actuator与spring-boot-admin
在上一篇中,通过restful api的方式查看信息过于繁琐,也不直观,效率低下.当服务过多的时候看起来就过于麻烦,每个服务都需要调用不同的接口来查看监控信息. SBA SBA全称spring boo ...
- Angular——$http
基本介绍 $http用于向服务端发起异步请求,同时还支持多种快捷方式如$http.get().$http.post().$http.jsonp.$hhtp也是属于内置服务的一种,这里特意提出来写一篇用 ...
- HTML meta信息含义
<meta name="viewport" content="width=device-width,initial-scale=1.0"> cont ...
- C++调用Com
需求:1.创建myCom.dll,该COM只有一个组件,两个接口: IGetRes--方法Hello(), IGetResEx--方法HelloEx() 2.在工程中导入组件或类型库 #im ...
- centos7服务器安装fail2ban配合Firewalld防护墙防止SSH爆破与防护网站CC攻击
centos7服务器安装fail2ban配合Firewalld防护墙防止SSH爆破与防护网站CC攻击 1.检查firewalld是否启用 #如果您已经安装iptables建议先关闭 service i ...
- CAD在一个点构造选择集
主要用到函数说明: IMxDrawSelectionSet::SelectAtPoint 在一个点构造选择集.详细说明如下: 参数 说明 [in] IMxDrawPoint* point 点坐标 [i ...