【Aizu - 0118】Property Distribution
-->Property Distribution
原文是日语,算了算了,直接上我大中华母语吧
Descriptions:
在H * W的矩形果园里有苹果、梨、蜜柑三种果树, 相邻(上下左右)的同种果树属于同一个区域,给出果园的果树分布,求总共有多少个区域。
Input
多组数据,每组数据第一行为两个整数H、W(H <= 100, W <= 100), H =0 且 W = 0代表输入结束。以下H行W列表示果园的果树分布, 苹果是@,梨是#, 蜜柑是*。
Output
对于每组数据,输出其区域的个数。
Sample Input
10 10
####*****@
@#@@@@#*#*
@##***@@@*
#****#*@**
##@*#@@*##
*@@@@*@@@#
***#@*@##*
*@@@*@@##@
*@*#*@##**
@****#@@#@
0 0
Output for the Sample Input
33
题目链接:
https://vjudge.net/problem/Aizu-0118
dfs加染色吧 比较经典的入门题
偷偷告诉你们 样例只有一组哦
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 105
using namespace std;
int n,m;
int num;//总共几种颜色
int vis[Maxn][Maxn];//染色计数
char mp[Maxn][Maxn];//原始地图
int dt[][]= {{,},{-,},{,},{,-}};//4个方向
void dfs(int x,int y,char ch)//横纵坐标 那个地方的字母
{
if(vis[x][y])
return;
vis[x][y]=num;
for(int i=; i<; i++)
{
int tx=x+dt[i][];
int ty=y+dt[i][];
if(!vis[tx][ty]&&mp[tx][ty]==ch)//没有被染色且这个地方是"ch"
dfs(tx,ty,ch);
}
}
int main()
{
while(cin>>n>>m,n+m)
{
num=;//初始化
MEM(mp,'X');
MEM(vis,);
for(int i=; i<n; i++)//读入地图
for(int j=; j<m; j++)
cin>>mp[i][j];
for(int i=; i<n; i++)//开始搜索
for(int j=; j<m; j++)
{
if(!vis[i][j]&&mp[i][j]!='X')
{
num++;
dfs(i,j,mp[i][j]);
}
}
cout<<num<<endl;
}
}
【Aizu - 0118】Property Distribution的更多相关文章
- 【codeforces 727D】T-shirts Distribution
[题目链接]:http://codeforces.com/problemset/problem/727/D [题意] 给你6种尺寸的衣服; 他们的尺码依次为S, M, L, XL, XXL, XXXL ...
- 【CodeForces - 1167C 】News Distribution(并查集)
News Distribution 题意 大概就是分成几个小团体,给每个人用1 - n编号,当对某个人传播消息的时候,整个小团体就知道这个消息,输出 分别对1 - n编号的某个人传递消息时,有多少人知 ...
- 【Aizu 2305】Beautiful Currency
题 题意 给你n个货币价格,然后通过调整一些货币的大小,使得所有比自己小的货币都是该货币的约数,调整前第 i 货币为a,调整后为b 那么变化率为 ri=|a-b|/a ,总变化率为max(ri).求最 ...
- 【Aizu - ALDS1_7_A】Rooted Trees(树的表达)
Rooted Trees Descriptions: A graph G = (V, E) is a data structure where V is a finite set of vertice ...
- 【Aizu - 0005 】GCD and LCM
GCD and LCM Descriptions: Write a program which computes the greatest common divisor (GCD) and the l ...
- 【Aizu - ALDS1_1_C】Prime Numbers(素数筛法)
Prime Numbers Descriptions: A prime number is a natural number which has exactly two distinct natur ...
- 【Aizu - 0033】Ball (简单搜索)
-->Ball 原文是日语,这里直接写中文了 Descriptions: 如图所示,容器中间有一枢轴,下方分为两路.容器上方开口,从1到10连续编号的小球从容器开口A放入.通过调整枢轴E的方向, ...
- 【Aizu - 0121】Seven Puzzle (反向bfs)
-->Seven Puzzle 原文是日语 这里就直接写中文了 Descriptions: 7拼图由8个正方形的卡和这些卡片完全收纳的框构成.每张卡都编号为0, 1, 2, …, 7,以便相互 ...
- 【Aizu - 0525】Osenbei (dfs)
-->Osenbei 直接写中文了 Descriptions: 给出n行m列的0.1矩阵,每次操作可以将任意一行或一列反转,即这一行或一列中0变为1,1变为0.问通过任意多次这样的变换,最多可以 ...
随机推荐
- jquery layer插件弹出弹层 结构紧凑,功能强大
/* 去官方网站下载最新的js http://sentsin.com/jquery/layer/ ①引用jquery ②引用layer.min.js */ 事件触发炸弹层可以自由绑定,例如: $('# ...
- TASM 5.0 安装及使用教程
安装TASM 5.0很简单,您只需要下载本站[相关工具]中的"TASM50.zip"文件,解压后在Windows9x/NT下执行"INSTALL.EXE"即可开 ...
- WPF 4 DataGrid 控件(基本功能篇)
原文:WPF 4 DataGrid 控件(基本功能篇) 提到DataGrid 不管是网页还是应用程序开发都会频繁使用.通过它我们可以灵活的在行与列间显示各种数据.本篇将详细介绍WPF 4 中 ...
- Hermite曲线插值
原文 Hermite Curve Interpolation Hermite Curve Interpolation Hamburg (Germany), the 30th March 1998. W ...
- 【C#】解决MouseHook捕获鼠标动作,在有些电脑上SetWindowsHookEx失败返回0的问题
原文:[C#]解决MouseHook捕获鼠标动作,在有些电脑上SetWindowsHookEx失败返回0的问题 最近在debug鼠标位置捕获的功能时发现在其中的一台开发电脑上,SetWindowsHo ...
- 在 __CC_ARM 编译器环境下,使用$Sub$$ 与 $Super$$ 的“补丁”功能
$Sub$$ 与 $Super$$ 的“补丁”功能(详见 ARM® Compiler v5.06 for µVision® armlink User Guide): 这是一种特殊模式:用于有一个已经存 ...
- 分布式文件系统的比较,115网盘用了fastdfs
分布式文件系统 分布式文件系统,作为网盘的基础,应用底层文件管理.而分布式文件系统之上,用户文件的权限,用户目录管理都是由非分布式文件系统管理. 分布式文件系统需要关心的主要内容: 文件分布/数据分布 ...
- ML:机器学习中常用的Octave语句
coursera上吴恩达的机器学习课程使用Octave/Matlab实现算法,有必要知道Octave简单的语句.最重要的:在遇到不会的语句,使用'''help '''或者'''doc '''查看官方文 ...
- 静态dll的问题终于搞定了
导入plugin,构建qapplicationhttps://forum.qt.io/topic/60940/qt-static-dll-x64-using-qapplication-issues/2 ...
- How to trim and edit videos in Photos for OS X
Don't let the name fool you, Photos for OS X also stores all your videos. Whether you synced them fr ...