http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=46522

简单DFS,题目翻译参考  http://blog.csdn.net/synapse7/article/details/14453017

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define maxn 1000000000
#define N 110
using namespace std; char filed[N][N];
int w,h,sum;
int dir[][]={-,,,,,,,-}; void dfs(int x,int y,char c)
{
for(int i=;i<;i++)
{
int xx=x+dir[i][];
int yy=y+dir[i][];
if(xx>=&&xx<h&&yy>=&&yy<w&&filed[xx][yy]==c)
{
filed[xx][yy]='.';
dfs(xx,yy,c);
}
}
}
int main()
{
//freopen("a.txt","r",stdin);
while(~scanf("%d%d",&h,&w)&&w+h)
{
getchar();
for(int i=;i<h;i++)
scanf("%s",filed[i]);
sum=;
for(int i=;i<h;i++)
for(int j=;j<w;j++)
if(filed[i][j]!='.')
{
dfs(i,j,filed[i][j]);
filed[i][j]='.';
sum++;
}
//printf("%d %d\n",a,b);
printf("%d\n",sum);
}
return ;
}

AOJ 0118 Property Distribution (DFS)的更多相关文章

  1. AOJ 0118: Property Distribution (简单DFS)

    题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0118 题意:给定一个矩阵,同类字符相连的为一个块,问总共有几个块. 输入 ...

  2. AOJ 0118 Property Distribution【DFS】

    题意:在H * W的矩形果园里有苹果.梨.蜜柑三种果树, 相邻(上下左右)的同种果树属于同一个区域,给出果园的果树分布,求总共有多少个区域. 输入:多组数据,每组数据第一行为两个整数H,W(H < ...

  3. aoj 0118 Property Distribution

    タナカ氏が HW アールの果樹園を残して亡くなりました.果樹園は東西南北方向に H × W の区画に分けられ.区画ごとにリンゴ.カキ.ミカンが植えられています.タナカ氏はこんな遺言を残していました. ...

  4. Property Distribution(DFS)

    Property Distribution タナカ氏が HW アールの果樹園を残して亡くなりました.果樹園は東西南北方向に H×W の区画に分けられ.区画ごとにリンゴ.カキ.ミカンが植えられています. ...

  5. 【Aizu - 0118】Property Distribution

    -->Property Distribution 原文是日语,算了算了,直接上我大中华母语吧  Descriptions: 在H * W的矩形果园里有苹果.梨.蜜柑三种果树, 相邻(上下左右)的 ...

  6. New Year and Old Property :dfs

    题目描述: Limak is a little polar bear. He has recently learnt about the binary system. He noticed that ...

  7. AOJ 0033 Ball【DFS】

    有一个筒,从A口可以放球,放进去的球可通过挡板DE使其掉进B管或C管里,现有带1-10标号的球按给定顺序从A口放入,问是否有一种控制挡板的策略可以使B管和C管中的球从下往上标号递增. 输入: 第一行输 ...

  8. AOJ 0118 深度优先搜索

    日文题... 题意:一个面积为H*W的果园,种了苹果,梨和蜜柑.相邻(上下左右)的果树属于同一个区域,问果园共有多少个区域. 分析:迷宫问题.对于每一个格子,可以用深度优先搜索把相同果树的格子遍历并标 ...

  9. AOJ.863 分书问题 (DFS)

    题意分析 现有n个人,n种书,给出每人对n种书的喜欢列表,求有多少种方案满足以下条件: 1.每个人都分得自己喜欢的书: 2.每个人分得书的种类各不相同,即所有种类的书均得到分配 1.采用生成测试法 生 ...

随机推荐

  1. 表单<form></form>提交方式的区别

    <form action="" method="get/post"> 表单<form></form>的提交方式有两种:pos ...

  2. 如需在APP中使用腾讯QQ登陆,需提前申请获取腾讯QQ的APPKEY和APPSecret。

    如需在APP中使用腾讯QQ登陆,需提前申请获取腾讯QQ的APPKEY和APPSecret. 申请流程如下: 步骤1:登陆腾讯开放平台.链接地址: http://open.qq.com/ . 步骤2:填 ...

  3. 移动端展示pdf(在线打开pdf)

    需求:在手机微信浏览器或者其他浏览器中打开pdf 准备:前端插件:查找pdf.js  官网地址:http://mozilla.github.io/pdf.js/ 在官网中下载demo 注释:pdf的d ...

  4. web.xml 加载顺序

    参考网址: 上下文对象>监听>过滤器>servlet 1.先加载上下文对象 <!-- 初始化Spring classpath*:spring/applicationContex ...

  5. 5 Transforms 转移 笔记

    5 Transforms 转移 笔记   Transforms    Unfortunately, no one can be told what the Matrix is. You have to ...

  6. yii项目开发配置

    Clone项目 git clone https://gitee.com/s***/dianshang.git 安装yii php ini 选择 [0] Development 安装扩展 copy co ...

  7. [转] NTFS Permission issue with TAKEOWN & ICACLS

    (转自:NTFS Permission issue with TAKEOWN & ICACLS - SAUGATA   原文日期:2013.11.19) Most of us using TA ...

  8. Ubuntu14.04环境下java web运行环境搭建

    1.jdk安装 将下载好的安装包上传至/home目录解压 tar -zxvf jdk-8u71-linux-x64.tar.gz 执行 vim /etc/profile 在末尾添加java环境变量(J ...

  9. Python3.0 操作MySQL数据库执行SQL语句

    py3不支持MySQLdb,需要导入pymysql模块 # coding: utf-8 # Team : Quality Management Center # Author:Carson # Dat ...

  10. css 动态导入css文件 @import 动态js加载 都是静态的

    @import "http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.css" /*-防止各大cdn公共库加载地址失效 ...