Problem UVA1103-Ancient Messages

Accept: 1176  Submit: 6103

Time Limit: 3000 mSec

Problem Description

 Input

 Output

 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

00000000000000000000000000000000000000

0 0

Sample output

Case 1: AKW

Case 2: AAAAA

题解:这个题重在脑洞,看出来联通块的个数与字母之间的关系的确不容易(我是没看出来)。开了脑洞之后问题就简单多了,先对最外面的白色区域dfs一下,然后就是dfs各个黑色区域,先把他们包围的联通块的范围划出来,然后计数里面的联通块个数,说的时候这划区域与计数是分开的,其实实现的时候是在一起的,划区域的时候如果碰到了白格,就停下来先对这个白格所在的联通块进行dfs,顺便记个数,区域划完了,计数也就搞定了

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std; const int maxn = +,maxm = +;
const int converse[][] =
{
{,,,},{,,,},{,,,},{,,,},
{,,,},{,,,},{,,,},{,,,},
{,,,},{,,,},{,,,},{,,,},
{,,,},{,,,},{,,,},{,,,}
}; char gra[maxn][maxm];
int buf[maxn][maxm<<];
int n,m,cnt;
int dir[][] = {{,},{,},{-,},{,-}}; inline bool Judge(int x,int y){
if(<=x && <=y && x<n && y<m) return true;
else return false;
} void dfsw(int x,int y,int num){
buf[x][y] = num;
int xx,yy;
for(int i = ;i < ;i++){
xx = x+dir[i][],yy = y+dir[i][];
if(Judge(xx,yy) && buf[xx][yy] == ){
dfsw(xx,yy,num);
}
}
} void dfsn(int x,int y,int num){
buf[x][y] = num;
int xx,yy;
for(int i = ;i < ;i++){
xx = x+dir[i][],yy = y+dir[i][];
if(Judge(xx,yy)){
if(buf[xx][yy] == ) dfsn(xx,yy,num);
else if(buf[xx][yy] == ){
cnt++;
dfsw(xx,yy,-);
}
}
}
} void map_print(){
for(int i = ;i < n;i++){
for(int j = ;j < m;j++){
printf("%d ",buf[i][j]);
}
printf("\n");
}
} int sum[];
char q[] = {'W','A','K','J','S','D'};
int iCase = ; int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
while(~scanf("%d%d",&n,&m) && (n||m)){
memset(buf,,sizeof(buf));
for(int i = ;i <= n;i++){
scanf("%s",gra[i]+);
for(int j = ;j <= (int)strlen(gra[i]+);j++){
int y = (j-)<<;
if('a'<=gra[i][j] && gra[i][j]<='z'){
for(int k = ;k < ;k++){
buf[i][y+k+] = converse[gra[i][j]-'a'+][k];
}
}
else{
for(int k = ;k < ;k++){
buf[i][y+k+] = converse[gra[i][j]-''][k];
}
}
}
}
n = n+,m = *m+;
//map_print();
dfsw(,,-);
int flag = ;
memset(sum,,sizeof(sum));
for(int i = ;i < n;i++){
for(int j = ;j < m;j++){
if(buf[i][j] == ){
cnt = ;
dfsn(i,j,flag);
flag++;
sum[cnt]++;
}
}
}
//map_print();
printf("Case %d: ",iCase++);
if(sum[] != ) for(int i = ;i < sum[];i++) printf("%c",'A');
if(sum[] != ) for(int i = ;i < sum[];i++) printf("%c",'D');
if(sum[] != ) for(int i = ;i < sum[];i++) printf("%c",'J');
if(sum[] != ) for(int i = ;i < sum[];i++) printf("%c",'K');
if(sum[] != ) for(int i = ;i < sum[];i++) printf("%c",'S');
if(sum[] != ) for(int i = ;i < sum[];i++) printf("%c",'W');
printf("\n");
}
return ;
}

UVA1103-Ancient Messages(脑洞+dfs)的更多相关文章

  1. HDU 3839 Ancient Messages(DFS)

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

  2. hdu 3839 Ancient Messages (dfs )

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

  3. Uva1103 Ancient Messages

    题意:识别图中的象形文字.但是,图形可以任意的拉伸,但不能拉断. 分析:这种题如果图形没有特征是不可做类型的题,不过观察图形可以发现每个图形中的洞的数量是一定的,我们只需要数出每一个封闭图形的洞数就能 ...

  4. K - Ancient Messages(dfs求联通块)

    K - Ancient Messages Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

  5. UVA1103 古代象形符号 Ancient Messages 题解

    题目链接: https://www.luogu.org/problemnew/show/UVA1103 题目分析: 我们可以先进行矩阵的还原 for(int k=1;k<=4;k++) { a[ ...

  6. UVA - 1103Ancient Messages(dfs)

    UVA - 1103Ancient Messages In order to understand early civilizations, archaeologists often study te ...

  7. UVa 1103 Ancient Messages(二重深搜)

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

  8. Ancient Messages UVA - 1103

    题目链接:https://vjudge.net/problem/UVA-1103 题目大意:每组数据包含H行W列的字符矩阵(H<=200,W<=50) 每个字符为为16进制  你需要把它转 ...

  9. UVa 1103 (利用连通块来判断字符) Ancient Messages

    本题就是灵活运用DFS来求连通块来求解的. 题意: 给出一幅黑白图像,每行相邻的四个点压缩成一个十六进制的字符.然后还有题中图示的6中古老的字符,按字母表顺序输出这些字符的标号. 分析: 首先图像是被 ...

随机推荐

  1. .Net敏捷开发框架6.1.6.2版本,联系QQ:6539471

    演示地址:www.fishcmonkey.com .NET敏捷开发框架 6.1.6.2 版本发布 新增手机流程-我的流程(可查看流程进度和表单内容) 新增手机流程-待办任务(可查看流程进度和表单内容, ...

  2. C# 语句 分支语句 switch----case----.

    第二种分支语句  switch..case. switch(一个变量){ case 值:要执行的代码段;break; case 值:要执行的代码段;break; ... ... ... default ...

  3. 【测试记录】EF插入查询性能

    介绍     背景什么就不提了,无外乎出现了大数据需要处理.简单的说就是我测试了EF正常的插入以及一个优化小方式而已,然后做了查询记录.其余没有什么,写这篇只是为了记录结果方便以后数据参考吧. 代码介 ...

  4. 10.C++-构造函数初始化列表、类const成员、对象构造顺序、析构函数

    首先回忆下,以前学的const 单独使用const修饰变量时,是定义的常量,比如:const int i=1; 使用volatile const修饰变量时,定义的是只读变量 使用const & ...

  5. 【原】Spring AOP实现对Redis的缓存同步

    前言:刚开始采用spring cache作为缓存数据,到后面发现扩展性不灵活,于是基于sprig cache原理自定义一套规则用于缓存数据. 请求过程: 根据请求参数生成Key,后面我们会对生成Key ...

  6. 【shell编程】1、shell编程简介

    Shell本身是一个用C语言编写的程序,它是用户使用Unix/Linux的桥梁,用户的大部分工作都是通过Shell完成的.Shell既是一种命令语言,又是一种程序设计语言.作为命令语言,它交互式地解释 ...

  7. Python 简单分页思路

    一: li = [] for i in range(1000): li.append(i) while True: p = input('input page: ') p = int(p) start ...

  8. Python 函数的作用域

    python中的作用域有4种: 名称 介绍 L local,局部作用域,函数中定义的变量: E enclosing,嵌套的父级函数的局部作用域,即包含此函数的上级函数的局部作用域,但不是全局的: B ...

  9. encodeURIComponent编码时为什么要编码两次

    Why 要对url进行编码? 当使用地址栏提交查询参数时,如果不编码,非英文字符会按照操作系统的字符集进行编码提交到服务器,服务器会按照配置的字符集进行解码,所以如果两者不一致就会导致乱码.   Wh ...

  10. 【读书笔记】iOS-iOS的UI自动化测试

    1,Instruments iOS自带的自动化测试工具. 2,TuneupJs  最早的iOS自动化测试工具 https://github.com/alexvollmer/tuneup_js 3,yn ...