Aizu-0118 Property Distribution
来源:互联网 发布:百胜erp软件下载 编辑:程序博客网 时间:2024/05/29 19:30
/************************************************* Author :somniloquy* Created Time :2015/10/30 14:00:50 ************************************************/#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>using namespace std;const int hw_max = 100 + 5;char graph[hw_max][hw_max];int sign[hw_max][hw_max];int h, w, ans;int dx[4] = {-1, 1, 0, 0};int dy[4] = {0, 0, -1, 1};struct node{ int x; int y; char mark;} start;void dfs(node now){ for(int i = 0; i < 4; i ++) { node next = now; next.x += dx[i]; next.y += dy[i]; if(next.x >= 0 && next.x < h && next.y >= 0 && next.y < w && next.mark == graph[next.x][next.y] && !sign[next.x][next.y]) { sign[next.x][next.y] = 1; dfs(next); } }}int main(void){ while(~scanf("%d %d", & h, & w)) { getchar(); if(!h && !w) break; memset(sign, 0, sizeof(sign)); ans = 0; for(int i = 0; i < h; i ++) { for(int j = 0; j < w; j ++) scanf("%c", & graph[i][j]); getchar(); } for(int i = 0; i < h; i ++) { for(int j = 0; j < w; j ++) { if(!sign[i][j]) { start.x = i; start.y = j; start.mark = graph[i][j]; dfs(start); ans ++; } } } printf("%d\n", ans); } return 0;}
题目:
在H * W的矩形果园里有苹果、梨、蜜柑三种果树, 相邻(上下左右)的同种果树属于同一个区域,给出果园的果树分布,求总共有多少个区域。 (原题的样图中苹果为リ,梨为カ,蜜柑为ミ, 图中共10个区域)
输入:
多组数据,每组数据第一行为两个整数H,W(H <= 100, W <= 100), H =0 且 W = 0代表输入结束。以下H行W列表示果园的果树分布, 苹果是@,梨是#, 蜜柑是*。
输出:
对于每组数据,输出其区域的个数。
题解:
日文题..
0 0
- Aizu-0118 Property Distribution
- Aizu-0118 Property Distribution(深搜)
- aizu/aoj-0118-Property Distribution
- Property Distribution Aizu
- 【算法渣渣的逆袭之路】Property Distribution Aizu - 0118
- AOJ--0118 Property Distribution
- AOJ 0118 Property Distribution (DFS)
- AOJ 0118 Property Distribution (BFS)
- AOJ 0118 Property Distribution 题解
- [DFS] AOJ 0118 Property Distribution
- Aoj 0118 Property Distribution【dfs】
- AOJ 0118 Property Distribution 【DFS】
- [挑战程序设计竞赛] AOJ 0118 - Property Distribution
- AOJ 0118 Property Distribution (dfs)
- AOJ 0118 Property Distribution {深度优先搜索}
- AOJ 0118 Property Distribution (果园分类)
- Property Distribution(AOJ 0118)深度优先搜索
- AOJ 0118: Property Distribution (简单DFS)
- object转换数组
- CRichEditCtrl
- 学习笔记:如何成为一个优秀的scrum master
- nodeJS第二章
- 一台机器上同时部署多个tomcat服务
- Aizu-0118 Property Distribution
- mysql数据库安装过程中遇见的问题及解决办法
- Git常用命令速查04 - 提交历史
- js从写alert样式
- java事件处理机制(自定义事件)
- Java中的过滤器doFilter里的chain.doFilter()函数理解
- oracle系统包——dbms job用法(oracle定时任务)
- 51nod 1069 Nim游戏 (博弈论)
- MD5加密算法的java实现