POJ 1988 Cube Stacking( 带权并查集 ) 非常棒的一道题!借鉴"找回失去的"博客 链接:传送门 题意: P次查询,每次查询有两种: M x y 将包含x的集合移动到y上面 C x, 计算x下面有几个元素.用p[x]表示x的根结点, 思路:cnt[x] 表示x所在集合的元素个数,top[x] 表示x上面有几个元素.每次进行路径压缩时,top[x] 都要加上 top[ par[x] ],cnt 和 par 的操作就是并查集的基本操作.最后计算结果是用 x 所在集合元素…
题意: 可以这样理解,有n快方形积木,一开始都是单独的放到哪,然后有两种操作 1 M a b 把a所在的那一堆落到b所在那一堆的上面(一开始自己是一堆) 2 C a 问a下面有多少个积木 思路: 感觉很久以前杭电上见过这个题目,比较简单的带权并查集,我们可以维护两个权来满足要求,第一个就是记录集合元素个数,就是合并的时候更新a所在的祖宗节点的距离权值,第二个权值就是距离权值,记录每个元素距离根节点的距离,然后更新就是简单更新没啥说的,还有就是简简单单敲完提交后WA了…
传送门 Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42463 Accepted: 13065 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang D…
True Liars Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2713 Accepted: 868 Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exha…
Navigation Nightmare Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 5939 Accepted: 2102 Case Time Limit: 1000MS Description Farmer John's pastoral neighborhood has N farms (2 <= N <= 40,000), usually numbered/labeled 1..N. A series o…
C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are…
B. Coach 题目连接: http://www.codeforces.com/contest/300/problem/A Description A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university progra…
Travel Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5441 Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is traveling in the Undirected Kingdom. There are n cities and m…
Navigation Nightmare Description Farmer John's pastoral neighborhood has N farms (2 <= N <= 40,000), usually numbered/labeled 1..N. A series of M (1 <= M < 40,000) vertical and horizontal roads each of varying lengths (1 <= length <= 100…
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Back to Underworld Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Description The Vampires and Lykans are fighting each other to death. The war has become so fierc…