【dfs】POJ2386湖计数】的更多相关文章

Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34735   Accepted: 17246 Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 10…
P1596 [USACO10OCT]湖计数Lake Counting 题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W'…
题目链接 https://www.luogu.org/problemnew/show/P1596 题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains eit…
题意:给定一个有向图,然后你可能改变某一些边的方向,然后就形成一种新图,让你求最多有多少种无环图. 析:假设这个图中没有环,那么有多少种呢?也就是说每一边都有两种放法,一共有2^x种,x是边数,那么如果有环呢?假设x是这个连通块的边数, y是这个环的边数,那么就一共有2^x * (2 ^ y - 2) 种,减去这两种就是一边也不变,和所有的边都就变,这样就形成环了. 那么怎么计算呢?这个题的边很特殊,所以我们可以利用这个特征,我们在每个连通块时,用vis记录一下开始的父结点,用cnt记录每一个到…
https://www.luogu.org/problemnew/show/P1596 连通块水题... 大体思路是找到是水坑的坐标然后就开始不断递归,往八个方向搜,把连在一起的都标记一遍直到找不到为止 以下是本蒟蒻的代码 #include <bits/stdc++.h>//万能头 using namespace std; ][]; ]={,-,-,-,,,,,};//x方向 ]={,-,,,-,,-,,};//y方向 ; void dfs(int x,int y) { a[x][y]='.'…
题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John wo…
\(problem\) 其实这题吧\(DFS\)好写一点(大雾 所以就不讲\(DFS\)了 em \(BFS\)的话 主要是 判重. 方向. 队列.(没了吧 至于位置 用两个队列?还是\(pair\)?还是结构体? \[\text{结构体大法好啊.emm}\] #ifdef Dubug #endif #include <bits/stdc++.h> using namespace std; typedef long long LL ; inline LL In() { LL res(0),f(…
可爱的题面君~~ 个人感觉这题还是很简单的,就是一个完全不加工的找联通块个数 个人解题思路是先读入,然后循环一遍,遇到水就dfs,并把这个w所在的联通块“删除”,并在答案上加一 最后输出答案 具体注释看程序::: #include<cmath> #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; int n,m…
题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John wo…
湖计数描述由于最近的降雨,水汇集在不同的地方,在农民约翰的领域,这是代表一个长方形的N×M(1μ= 100:1 = M = 100)平方.每一方都包含水(’w')或干燥的土地(“.”).农民约翰想弄清楚在他的田里已经形成了多少个池塘.一个池塘是一个连接的正方形与水在他们,其中一个正方形被认为是相邻的所有八个它的邻居.给定一个农民约翰的领域的图表,确定他有多少个池塘.输入行1:两个空格分隔的整数:N和M*线2 .. N + 1:M字符每行代表一行的农民约翰的领域.每个字符是“W”或“.”.字符之间…