POJ 2386 Lake Counting
来源:互联网 发布:怎么把淘宝小号养到2心 编辑:程序博客网 时间:2024/06/06 18:40
Description:
Given a diagram of Farmer John's field, determine how many ponds he has.
* Lines 2..N+1: M characters per line representing one row of Farmer John's field. Each character is either 'W' or '.'. The characters do not have spaces between them.
10 12W........WW..WWW.....WWW....WW...WW..........WW..........W....W......W...W.W.....WW.W.W.W.....W..W.W......W...W.......W.
3
There are three ponds: one in the upper left, one in the lower left,and one along the right side.
题目大意:
求图中联通块个数, ’W‘为有效可以拓展到8个方向。
解题思路:
裸的DFS练习, 别忘记判断越界。
代码:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <cmath>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;
/*tools:
*ios::sync_with_stdio(false);
*freopen("input.txt", "r", stdin);
*/
typedef long long ll;
typedef unsigned long long ull;
const int dir[9][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1, 0, 0};
const ll ll_inf = 0x7fffffff;
const int inf = 0x3f3f3f;
const int mod = 1000000;
const int Max = (int) 2e5 + 7;
char str[Max], ans[Max];
int num[Max], vis[Max];
int main() {
//freopen("input.txt", "r", stdin);
scanf("%d", str);
int len = strlen(str);
for (int i = 0; i < len; ++i) {
num[str[i]]++;
}
for (int i = 0; i < Max; ++i) {
if (num[i] > n / 2) {
printf("impossible\n");
break;
}
}
for (int i = 0; i < n; ++i) {
else {
for (int j = 0; j < n; ++j) {
if (str[i] != str[j] && !vis[j]) {
ans[j] = str[i];
vis[j] = 1;
}
}
}
}
return 0;
}
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ-2386-Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- Poj 2386 Lake Counting
- poj 2386 Lake Counting
- ArrayBlockingQueue
- 系统调用fork()、vfork()与clone()
- 一行一行读Java源码
- Yii2.0中在GridView添加字体图标按钮
- 洛谷p1091
- POJ 2386 Lake Counting
- JavaScript中window.onload事件的添加
- Python基础-迭代Iteration
- js中Map之基本用法
- leetcode 419. Battleships in a Board 战列舰的数量 + 一个新奇的循环遍历
- 哈尔滨理工大学第七届程序设计竞赛初赛 题集
- java jsp 页面下拉框 ajax异步加载数库数据
- springboot学习之启动类中的@SpringBootApplication注解
- python+django+sae