/*
* main.cpp
*
* Created on: 2014.7.12
*本栏目更多精彩内容:http://www.bianceng.cn/Programming/sjjg/
* Author: spike
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
class Program {
static const int MAX_N=20, MAX_M=20;
int N = 10, M = 12;
char field[MAX_N][MAX_M+1] = {
"W........WW.",
".WWW.....WWW",
"....WW...WW.",
".........WW.",
".........W..",
"..W......W..",
".W.W.....WW.",
"W.W.W.....W.",
".W.W......W.",
"..W.......W."};
void dfs(int x, int y) {
field[x][y] = '.';
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int nx = x+dx, ny = y+dy;
if (0<=dx&&nx<N&&0<=ny&&ny<=M&&field[nx][ny]=='W') dfs(nx, ny);
}
}
return;
}
public:
void solve() {
int res=0;
for (int i=0; i<N; i++) {
for (int j=0; j<M; j++) {
if (field[i][j] == 'W') {
dfs(i,j);
res++;
}
}
}
printf("result = %d\n", res);
}
};
int main(void)
{
Program P;
P.solve();
return 0;
}
result = 3
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有