hdu5438 Ponds】的更多相关文章

目录 题目地址 题干 代码和解释 参考 题目地址 hdu5438 题干 代码和解释 解答本题时参考了一篇代码较短的博客,比较有意思,使用了STL vector二维数组. 可以结合下面的示例代码理解: #include<iostream> #include<vector> using namespace std; int main() { vector<int> n[100]; int i; for(i=0;i<100;i++){ n[i].clear(); } n…
Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 533    Accepted Submission(s): 175 Problem Description Betty owns a lot of ponds, some of them are connected with other ponds by pipes, an…
Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 3204    Accepted Submission(s): 995 Problem Description Betty owns a lot of ponds, some of them are connected with other ponds by pipes, a…
Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 2677    Accepted Submission(s): 850 Problem Description Betty owns a lot of ponds, some of them are connected with other ponds by pipes, and th…
Time Limit: 1500/1000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others) Problem Description Betty owns a lot of ponds, some of them are connected with other ponds by pipes, and there will not be more than one pipe between two ponds. Ea…
Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=621 Description Betty owns a lot of ponds, some of them are connected with other ponds by pipes, and there will not be more than one…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5438 Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2237    Accepted Submission(s): 707 Problem Description Betty owns a lot of ponds, som…
Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Betty owns a lot of ponds, some of them are connected with other ponds by pipes, and th…
Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 282    Accepted Submission(s): 86 Problem Description Betty owns a lot of ponds, some of them are connected with other ponds by pipes, and…
Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1394    Accepted Submission(s): 467 Problem Description Betty owns a lot of ponds, some of them are connected with other ponds by pipes, a…
题意 不断删去度数为1的点,最后求有奇数个点的联通块的权值之和. 分析 存边的时候,要头尾都存这个边.用dfs或者队列删点,再用并查集或者dfs确定联通块,然后统计联通块的点数,最后累加. 我自己写的超时,然后参考了网上的题解.真郁闷. 代码 并查集 #include<cstdio> #include<queue> #include<vector> #define ll long long using namespace std; const int N = 1e4 +…
题意:给出一张无向图,每个节点有各自的权值,问在点数为奇数的圈中的点的权值总和是多少. 通过拓扑序的做法标记出所有非圈上的点,做法就是加每条边的时候将两点的入度都加一,然后将所有度数为1的点入队,删去它的所有边,即对没条边连的点度数减一,度数减为1继续入队,直到队列为空,入过队列的点都进行标记,表示该点不在圈上,那么剩余没有标记的点一定要么在圈上.要么是单点或自环.这时候只要对于每个没有访问过的节点,DFS遍历它的连通区域,记录点数和权值和,如果点数为奇数,则统计权值和.但是注意如果只有一个点,…
题意:给定一个图,然后让你把边数为1的结点删除,然后求连通块结点数为奇的权值和. 析:这个题要注意,如果删除一些结点后,又形成了新的边数为1的结点,也应该要删除,这是坑,其他的,先用并查集判一下环,然后再找连通环. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstrin…
题目传送门 题意:有一张无向图,度数小于2的点会被去掉,直到全都大于等于2,问连通块顶点数为奇数的权值和为多少 分析:首先DFS把度数小于2的vis掉,第二次DFS把属于同一个连通块的vis掉,检查是否为奇数个定点,是累加和.用sz[i]表示i点真实还连着的点的个数 代码: /************************************************ * Author :Running_Time * Created Time :2015/9/13 星期日 15:34:01…
题目: 给出一个无向图,将图中度数小于等于1的点删掉,并删掉与他相连的点,直到不能在删为止,然后判断图中的各个连通分量,如果这个连通分量里边的点的个数是奇数,就把这些点的权值求和. 思路: 先用拓扑排序删点并更新各个点的度数,然后用并查集判断各个连通分量里边的点个数的奇偶性就ok了. 代码: #include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #i…
2015 ACM/ICPC Asia Regional Changchun Online 题意:n个池塘,删掉度数小于2的池塘,输出池塘数为奇数的连通块的池塘容量之和. 思路:两个dfs模拟就行了 #include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include…
先dfs对度小于2的删边,知道不能删为止. 然后通过并查集来计算每一个分量里面几个元素. #include<iostream> #include<cstring> #include<vector> #define maxn 10010 #define LL __int64 using namespace std; int in[maxn],vis[maxn],p,pa[maxn],cou[maxn]; LL sum[maxn]; vector<int>mp[…
解析 对一个有向无环图(Directed Acyclic Graph,简称DAG)G进行拓扑排序,是将G中所有顶点排成一个线性序列,使得图中任意一对顶点u和v,若<u,v> ∈E(G),则u在线性序列中出现在v之前. 效果如图: 模板 void toposort(int map[MAX][MAX],int indegree[MAX],int n) { int i,j,k; for(i=0;i<n;i++) //遍历n次 { for(j=0;j<n;j++) //找出入度为0的节点…
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31474   Accepted: 15724 Description Due to recent rains, water has pooled in various places in Farmer John's field, which is repr…
POJ2152 树形dp,每次先dfs一遍求出距离再枚举所有点转移即可. #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; inline int read() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-'; ch=getcha…
[B007]Lake Counting[难度B]—————————————————————————————————————————— [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 <= 100; 1 <= M <= 100) square…
总结汇总:模板 int getmax_min(char s[]) {//字符串的最大表示法:返回最小数组下标 , j = , k = ; while(i < len && j < len) { k = ; while(s[i+k] == s[j+k] && k < len) k++; if(k == len) return min(i,j); if (s[i + k] < s[j + k]) > j) i = i + k + ; else i…
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') or dry land ('.'). Fa…
Lake Counting Time Limit: 1000MS     Memory Limit: 65536K Total Submissions: 17917     Accepted: 9069 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 <=…
Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30414   Accepted: 15195 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…
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2013    Accepted Submission(s): 830Special Judge Problem Description Your old uncle Tom inherited a piece of land from…
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3339    Accepted Submission(s): 1394Special Judge Problem Description Your old uncle Tom inherited a piece of land fro…
网址:http://acm.hdu.edu.cn/showproblem.php?pid=5438 Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 376    Accepted Submission(s): 116 Problem Description Betty owns a lot of ponds, some…
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1869    Accepted Submission(s): 777 Special Judge Problem Description Your old uncle Tom inherited a piece of land fr…
Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16802   Accepted: 8523 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 <= 100…