弄懂题意后  其实就是一个dfs

/*************************************************************************
> Author: xlc2845 > Mail: xlc2845@gmail.com
> Created Time: 2013年10月22日 星期二 16时20分43秒
************************************************************************/ #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#define maxn 210 using namespace std; int g[maxn][maxn];
int n, m, cnt;
int num[6];
char st[6] = {'A', 'D', 'J', 'K', 'S', 'W'};
char str[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
int s[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}
};
bool is_in(int x, int y)
{
if(x >= 0 && x <= n+1 && y >= 0 && y <= m+1)
return true;
return false;
}
void dfs(int x, int y)
{
if(!is_in(x, y) || g[x][y] != 0)
return;
g[x][y] = -1;
dfs(x + 1, y);
dfs(x - 1, y);
dfs(x, y - 1);
dfs(x, y + 1);
} void dfs2(int x, int y)
{
if(!is_in(x, y) || g[x][y] == -1)
return;
if(!g[x][y])
{
dfs(x, y);
cnt++;
return;
}
g[x][y] = -1;
dfs2(x + 1, y);
dfs2(x - 1, y);
dfs2(x, y - 1);
dfs2(x, y + 1);
} int main()
{
int ca = 1;
while(scanf("%d%d", &n, &m) == 2 && n+m)
{
memset(g, 0, sizeof(g));
memset(num, 0, sizeof(num));
for(int i = 1; i <= n; i++)
{
getchar();
char ch;
int len = 1;
for(int j = 0; j < m; j++)
{
scanf("%c", &ch);
for(int k = 0; k < 16; k++)
if(ch == str[k])
{
for(int l = 0; l < 4; l++)
g[i][len++] = s[k][l];
break;
}
}
}
m *= 4;
dfs(0, 0);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
if(g[i][j] == 1)
{
cnt = 0;
dfs2(i, j);
if(!cnt) num[5]++;
else if(cnt == 1) num[0]++;
else if(cnt == 2) num[3]++;
else if(cnt == 3) num[2]++;
else if(cnt == 4) num[4]++;
else num[1]++;
}
printf("Case %d: ", ca++);
for(int i = 0; i < 6; i++)
while(num[i]--)
printf("%c", st[i]);
puts("");
}
return 0;
}

uva 1103的更多相关文章

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

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

  2. Ancient Message (古埃及象形文字识别 Uva 1103)

    原题:https://uva.onlinejudge.org/external/11/1103.pdf 给一幅图(16进制), 判断图中有哪些象形文字. 只识别 这6个就可以 示例: 将16进制数据 ...

  3. Uva 1103 古代象形文字

    题目链接:http://vjudge.net/contest/140550#problem/B 紫书P163. 1.根据16进制图转成2进制图. 每个点dfs一下,马上就把最外围的连通分量编号求出来了 ...

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

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

  5. Uva 1103 Ancient Messages

    大致思路是DFS: 1. 每个图案所包含的白色连通块数量不一: Ankh : 1 ;  Wedjat : 3  ; Djed : 5   ;   Scarab : 4 ; Was : 0  ;  Ak ...

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

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

  7. UVA 1103 How Many O's?

    题目链接:UVA-11038 题意为给定n和m,求n和m之间(包含)的所有数包含的0的个数. 思路是,用cal(x)表示小于等于x的数包含的0的个数.则答案为cal(n)-cal(m-1). 再把求c ...

  8. Ancient Messages UVA - 1103

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

  9. Uva 1103 古代象形符号(dfs求连通块, floodfill, 进制转换)

    题意: 给定一个H行W列的字符矩阵(H<200, W < 50), 输入的是一个十六进制字符, 代表一行四个相邻的二进制, 1代表像素, 0代表没有像素. 然后要求判断输入的是以下哪些图形 ...

随机推荐

  1. ASP.NET二级域名站点共享Session状态

    我的前面一篇文章提到了如何在使用了ASP.NET form authentication的二级站点之间共享登陆状态, http://www.cnblogs.com/jzywh/archive/2007 ...

  2. python学习day1--python基础

    Python的优缺点 先看优点 Python的定位是“优雅”.“明确”.“简单”,所以Python程序看上去总是简单易懂,初学者学Python,不但入门容易,而且将来深入下去,可以编写那些非常非常复杂 ...

  3. XML中的Xpath解析的例子

    /*XPath 术语节点(Node)在 XPath 中,有七种类型的节点:元素.属性.文本.命名空间.处理指令.注释以及文档(根)节点.XML 文档是被作为节点树来对待的.树的根被称为文档节点或者根节 ...

  4. c# using 引用和别名的使用

    1.使用别名 在同时引用的两个命名空间中有相同的类型时,可以使用别名来区分.如下所示: using System; using System.Threading; using System.Timer ...

  5. c# DateTime时间格式和JAVA时间戳格式相互转换

    /// java时间戳格式时间戳转为C#格式时间 public static DateTime GetTime(long timeStamp) { DateTime dtStart = TimeZon ...

  6. OC9_文件操作

    // // main.m // OC9_文件操作 // // Created by zhangxueming on 15/6/19. // Copyright (c) 2015年 zhangxuemi ...

  7. java SimpleDateFormat非线程安全测试

    public class MyThread extends Thread { private SimpleDateFormat sdf; private String dateString; publ ...

  8. 膜拜 2014-2 (献给L之三)

    文/安然 深深的夜静静的想你细细的品味满满的甜蜜爱,心灵的对话让我流泪战栗谢谢你给我这么弥足珍贵的体会不能一生相随又有什么关系你一直都在我的爱就永不停息此生足以——献给心底的爱

  9. WinSCP列出’/’目录项出错

    无法获得目录列表 如图所示,使用百度云虚拟机时,FTP连接服务器,出现错提示,官方给出的说法是使用其他的FTP进行连接,但是之前成功连接过,查找资料后说是打开过png,mp3等媒体文件,切换路径时出错 ...

  10. oracle数据库如何保存SQL语句?

    比如:通过系统web页面自动生成了sql语句,insert into temp(select '1,2,3',to_date(sysdate,'yyyy--mm-dd hh24:mi:ss') fro ...