hdu-4496-D-City】的更多相关文章

给你n个点m条边,保证已经是个连通图,问每次按顺序去掉给定的一条边,当前的连通块数量. 与其正过来思考当前这边会不会是桥,不如倒过来在n个点即n个连通块下建图,检查其连通性,就能知道个数了 /** @Date : 2017-09-21 23:26:20 * @FileName: HDU 4496 并查集 逆向思维.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github…
思路:逆向并查集,逆向加入每一条边即可.在获取联通块数量的时候,直接判断新加入的边是否合并了两个集合,如果合并了说明联通块会减少一个,否则不变. AC代码 #include <cstdio> #include <cmath> #include <cctype> #include <algorithm> #include <cstring> #include <utility> #include <string> #incl…
http://acm.hdu.edu.cn/showproblem.php?pid=4496 题意: 给出n个顶点m条边的图,每次选择一条边删去,求每次删边后的连通块个数. 思路: 离线处理删边,从后往前处理变成加边,用并查集维护连通块个数.其实这题和BZOJ 1015差不多. #include<iostream> #include<cstdio> #include<cstring> using namespace std; int n, m, tot, num; ],…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4496. 思路:简单并查集应用,从后往前算就可以了. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define MAXN 10100 #define MAXM 1001000 struct Edge{ int u,v;…
学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个push_down 3 注意push_up 写法有点不一样,不过是可以改成一样的. 简单裸题*2 L - Atlantis  HDU - 1542 #include <iostream> #include <cstdio> #include <algorithm> #inclu…
Wow! Such City! Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others) Total Submission(s): 824    Accepted Submission(s): 310 Problem Description Doge, tired of being a popular image on internet, is considering moving…
题意:有n个城市,m条路,首先m条路都连上,接着输出m行,第i行代表删除前i行的得到的连通块个数 题解:正难则反,我们反向考虑使用并查集添边.首先每个点都没有相连,接着倒着来边添加边计算,当两个点父节点相同时连通块不变,否则-1 #include<set> #include<map> #include<queue> #include<stack> #include<cmath> #include<vector> #include<…
题目 熟能生巧...常做这类题,就不会忘记他的思路了... //可以反过来用并查集,还是逐个加边,但是反过来输出...我是白痴.....又没想到 //G++能过,C++却wa,这个也好奇怪呀... #include<stdio.h> #include<string.h> ]; ],y[],n,m,i,count,ans[],j; int find(int x) { //改成这样就不会超时了么好奇怪为什么 if(bin[x] == x)return x; return bin[x]…
题意:给定一个图,问你每次删除一条边后有几个连通块. 析:水题,就是并查集的运用,倒着推. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <queue> #include <…
题意:给出一个图,m条边,输出删除前i条边后该图的联通块的个数. 思路:刚开始想着是不是联通问题,后来看明白题意后知道,如果从最后一条边添加的话,答案就会出来了,就是并差集的操作. #include<stdio.h> #include<string.h> const int N=11000; int f[N],sum,a[N*10]; struct edge { int st,ed; }e[N*10]; int find(int a) { if(a!=f[a]) f[a]=find…
D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 840    Accepted Submission(s): 340 Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-ci…
Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-city. D-city has N D-points and M D-lines. Each D-line connects exactly two D-points. Luxer will destroy all the D-lines. The mayor of D-city wants…
D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 18    Accepted Submission(s): 15 Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-city…
D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2933    Accepted Submission(s): 1038 Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-…
貌似某大犇说过 正难则反,,, 题目说要对这张图进行删边,然后判断联通块的个数,那么就可以先把所有边都删掉,之后从后往前加边,若加的边两端点不在同一个联通块中, 那么此时联通快个数少一,否则不变 #include <cstdio> #include <cstring> #include <algorithm> + ; + ; int father[maxn]; int x1[maxm], x2[maxm]; int ans[maxm]; int n, m; int ge…
Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-city. D-city has N D-points and M D-lines. Each D-line connects exactly two D-points. Luxer will destroy all the D-lines. The mayor of D-city wants…
给出n个点和m条边,一条一条地删除边,问每次删除以后有多少个联通块. 分析:其实就是并查集的应用,只是前一阵子一直做图论思路一直囿于tarjan了..方法就是,记录每一条边,然后从最后一条边开始不断的加边,如果用并查集来判断联通块有没有减少即可. 代码如下: #include <stdio.h> #include <string.h> #include <algorithm> #include <set> using namespace std; typed…
题意:有N个星球,每个星球有自己的武力值.星球之间有M条无向边,连通的两个点可以相互呼叫支援,前提是对方的武力值要大于自己.当武力值最大的伙伴有多个时,选择编号最小的.有Q次操作,destroy为切断连接两点的边,query为查询某星球能不能向它人呼叫支援. 还是需要离线逆向并查集求解.思路和HDU 4496很相似,但是此处不一定是把所有边都删去,所以需要删边的情况建立出最终的状态.因为N可以到1e4,所以可以用map嵌套map的方式记录过程中被删去的边,最后再根据删除情况建立状态. 在合并时需…
F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1505 Appoint description: Description Bob is a strategy game programming specialist. In his new city building game the gaming enviro…
City Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 483    Accepted Submission(s): 203 Problem Description After many years, the buildings in HDU has become very old. It need to rebuil…
City Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 503    Accepted Submission(s): 213 Problem Description After many years, the buildings in HDU has become very old. It need to rebui…
The plan of city rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 616    Accepted Submission(s): 215 Problem Description News comes!~City W will be rebuilt with the expectation to become…
题目链接: Hdu 5352 MZL's City 题目描述: 有n各节点,m个操作.刚开始的时候节点都是相互独立的,一共有三种操作: 1:把所有和x在一个连通块内的未重建过的点全部重建. 2:建立一条双向路(x,y) 3:又发生了地震,p条路被毁. 问最后最多有多少个节点被重建,输出重建节点的最小字典序. 解题思路: 这几天正好在学匹配,但是昨天下午还是没有看出来这个是匹配题目.看了题解扪心自问了自己三次,是不是傻.就是把每个需要重建的节点x拆成k个点,然后对每个拆分后的点和与拆点在同一连通块…
HDU 4849 Wow! Such City! 题目链接 题意:依照题目中的公式构造出临接矩阵后.求出1到2 - n最短路%M的最小值 思路:就依据题目中方法构造矩阵,然后写一个dijkstra,利用d数组取求答案就可以 代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const long long…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5013 题意: 思路: 这里有错,是Hi(x)=sigama(Hji)(j属于x) const int N=18; int m,n; double p[N],H[N][N]; double f[N][1<<N]; double dp[N][1<<N]; double a[1<<N],aa[1<<N]; double pp[1<<N],qq[1<&…
Problem Description Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is built up by areas, in which there are streets, trees,factories and buildings. There is still some space i…
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17635    Accepted Submission(s): 5261   Problem Description A histogram is a polygon composed of a sequence of r…
最大01子矩阵和,就是一个矩阵的元素不是0就是1,然后求最大的子矩阵,子矩阵里的元素都是相同的. 这个题目,三个oj有不同的要求,hoj的要求是5s,poj是3秒,hdu是1秒.不同的要求就对应不同的难度,不同的逼格. 先看最low的, HOJ 1664 5秒钟的时间,够长了.我很容易想到可以最大子矩阵和来求解,二者本来就很像,关于最大子矩阵和这个博客里有介绍 最大子矩阵和 这里我们可以把F变成1,把R变成负无穷大,这样求解最大子矩阵和就可以得到答案 #include <iostream> #…
http://acm.hdu.edu.cn/showproblem.php?pid=4849 会有非常多奇怪的Wa的题.当初在西安就不知道为什么wa,昨晚做了,由于一些Sb错误也wa了非常久.这会儿怎么写都会AC. ... 收获: 1.还是基本都构思好在去写程序,由于当时没过.昨晚心里有阴影.敲得非常慢,并且最開始各种取模以防止漏掉,太保守了......以后一定先估算是不是须要取模防止TLE,当然时间够的话还是适当多取个模防止莫名其妙的错误.. 2.假设出错,注意參数是不是对的,最開始写好之后.…
题意  一个城市原来有l个村庄 e1条道路  又添加了n个村庄 e2条道路  后来后销毁了m个村庄  与m相连的道路也销毁了  求使全部未销毁村庄相互连通最小花费  不能连通输出what a pity! 还是非常裸的最小生成树  把销毁掉的标记下  然后prim咯  结果是无穷大就是不能连通的 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N =…