AOJ 0118 Property Distribution (DFS)
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)的更多相关文章
- AOJ 0118: Property Distribution (简单DFS)
题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0118 题意:给定一个矩阵,同类字符相连的为一个块,问总共有几个块. 输入 ...
- AOJ 0118 Property Distribution【DFS】
题意:在H * W的矩形果园里有苹果.梨.蜜柑三种果树, 相邻(上下左右)的同种果树属于同一个区域,给出果园的果树分布,求总共有多少个区域. 输入:多组数据,每组数据第一行为两个整数H,W(H < ...
- aoj 0118 Property Distribution
タナカ氏が HW アールの果樹園を残して亡くなりました.果樹園は東西南北方向に H × W の区画に分けられ.区画ごとにリンゴ.カキ.ミカンが植えられています.タナカ氏はこんな遺言を残していました. ...
- Property Distribution(DFS)
Property Distribution タナカ氏が HW アールの果樹園を残して亡くなりました.果樹園は東西南北方向に H×W の区画に分けられ.区画ごとにリンゴ.カキ.ミカンが植えられています. ...
- 【Aizu - 0118】Property Distribution
-->Property Distribution 原文是日语,算了算了,直接上我大中华母语吧 Descriptions: 在H * W的矩形果园里有苹果.梨.蜜柑三种果树, 相邻(上下左右)的 ...
- New Year and Old Property :dfs
题目描述: Limak is a little polar bear. He has recently learnt about the binary system. He noticed that ...
- AOJ 0033 Ball【DFS】
有一个筒,从A口可以放球,放进去的球可通过挡板DE使其掉进B管或C管里,现有带1-10标号的球按给定顺序从A口放入,问是否有一种控制挡板的策略可以使B管和C管中的球从下往上标号递增. 输入: 第一行输 ...
- AOJ 0118 深度优先搜索
日文题... 题意:一个面积为H*W的果园,种了苹果,梨和蜜柑.相邻(上下左右)的果树属于同一个区域,问果园共有多少个区域. 分析:迷宫问题.对于每一个格子,可以用深度优先搜索把相同果树的格子遍历并标 ...
- AOJ.863 分书问题 (DFS)
题意分析 现有n个人,n种书,给出每人对n种书的喜欢列表,求有多少种方案满足以下条件: 1.每个人都分得自己喜欢的书: 2.每个人分得书的种类各不相同,即所有种类的书均得到分配 1.采用生成测试法 生 ...
随机推荐
- Uediter的引用和取值
页面应用Uediter控件,代码如下: <tr> <td align="center" class="xwnr_j"> <asp: ...
- 微信官方UI库—WeUI
WeUI 为微信 Web 服务量身设计 概述 WeUI是一套同微信原生视觉体验一致的基础样式库,由微信官方设计团队为微信 Web 开发量身设计,可以令用户的使用感知更加统一.包含button.cell ...
- php查询快递信息
$code = 'shunfeng'; $invoice = '952255884068'; $test = getExpressDelivery($code,$invoice); function ...
- SQL Server性能调优——报表数据库与业务数据库分离
前段时间把公司的主数据库切了,分成业务库和报表库,业务库向报表库进行实时的Replication.这个项目的上线提升了系统的性能和可维护性,现在把设计时的考量和所做的工作重新回顾一下,作为备忘. 项目 ...
- [Windows Server 2012] MySQL移机方法
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:MySQL ...
- OpenGL VAO, VBO 使用简介
参照代码样例: // This function takes in a vertex, color, index and type array // And does the initializati ...
- JAVA 学习笔记 - 反射机制
1. JAVA反射机制的概念 2. 怎样实例化一个 Class对象 Class.forName(包名.类名); 对象.getClass(); 类.class; ================== ...
- sql server 强制关闭连接
USE master; GO DECLARE @SQL VARCHAR(MAX); SET @SQL='' SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID) FROM ma ...
- biff - 新到邮件提醒
总览 (SYNOPSIS) biff [ny ] 描述 (DESCRIPTION) Biff 通知系统在当前终端会话期间有新邮件是否提醒你. 支持的选项有 biff n 禁止新邮件提醒. y 开启新邮 ...
- TCP/IP 协议分层
协议分层 可能大家对OSI七层模型并不陌生,它将网络协议很细致地从逻辑上分为了7层.但是实际运用中并不是按七层模型,一般大家都只使用5层模型.如下: 物理层:一般包括物理媒介,电信号,光信号等,主要对 ...