随笔分类 - 并查集
摘要:链接:http://poj.org/problem?id=2031http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#problem/ABuilding a Space StationTime Limit:1000MSMemory Limit:30000KTotal Submissions:3578Accepted:1830DescriptionYou are a member of the space station engineering team, and are assigned a task in the const
阅读全文
摘要:RochambeauTime Limit:5000MSMemory Limit:65536KTotal Submissions:1603Accepted:556DescriptionNchildren are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three groups (it is possible that some group is empty). You don’t know who is
阅读全文
摘要:Connections in Galaxy WarTime Limit:3 Seconds Memory Limit:32768 KBIn order to strengthen the defense ability, many stars in galaxy allied together and built many bidirectional tunnels to exchange messages. However, when the Galaxy War began, some tunnels were destroyed by the monsters from another
阅读全文
摘要:How Many Answers Are WrongTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1384Accepted Submission(s): 562Problem DescriptionTT and FF are ... friends. Uh... very very good friends -________-bFF is a bad boy, he is always wooing TT to play the follo
阅读全文
摘要:题意:给你 N 件不同的商品,每件商品最多可以买一次。 每件物品对应两个值 pi di pi 表示物品的价值,di 表示可以买的最迟时间(也就是第一天到第 di 天都可以买这件物品) 规定:每天最多可以买一件物品,问你可以得到的最大价值。算法:贪心 看了KB神的题解,他用的并查集,等下贴个代码。思路【贪心版本】:将物品按照价值从大到小排序 依次枚举每件物品 从可以买的最后一天枚举,看是否可以买 注意:标记天数。思路【KB的并查集版本】:将物品按照价值从大到小排序 处理的时候选择最后的一个不冲突点。 ...
阅读全文
摘要:A Bug's LifeTime Limit:10000MSMemory Limit:65536KTotal Submissions:23484Accepted:7639DescriptionBackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender
阅读全文
摘要:算法:并查集。题意:给你 N 个农场 给定 M 条关系 :x y len dir 表示农场 y 在农场 x 的 dir 方向的 len 米处 输入 Q 个问题:x y index 在知道从从第一条关系到第 index 条关系的情况下,判断农场 x 和农场 y 的相对关系。 如果能判断,则输出相对关系:水平距离差 + 垂直距离差 如果不能判断,则输出 -1.注意:每组测试数据中的每个问题中的 index 是按照从小到大的顺序给出的,所以使得问题简单化。思路:p[] 记录父亲节...
阅读全文
摘要:Wireless NetworkTime Limit:10000MSMemory Limit:65536KTotal Submissions:13361Accepted:5659DescriptionAn earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the n
阅读全文
摘要:Cube StackingTime Limit:2000MSMemory Limit:30000KTotal Submissions:15951Accepted:5448Case Time Limit:1000MSDescriptionFarmer John and Betsy are playing a game with N (1 const int maxn = 30000+10; int p[maxn];
int r[maxn]; //下面的个数
int sum[maxn]; //总个数 int find(int x)
{ if(x == p[x]) return x;...
阅读全文
摘要:转载来自:http://www.cnblogs.com/huangfeihome/archive/2012/09/07/2675123.html并查集。 首先,以为k个询问中的I是乱序的,直接被吓傻了,后来看讨论版才发现I是升序的…… 这道题让我对并查集有一个新的认识:根的代表性是非常强的!并查集里如果某个节点的改动会影响到整个并查集的所有节点,那么,在union_set的时候只需要改动根节点就可以了,当然,在find_set函数里要对所有节点进行更新(这相当于一种延时标记)。我们知道,find_set函数走了两条路,一条是前往根的路,一条是从跟返回的路,那么,如果发现根已经被改动,必须在..
阅读全文
摘要:Find them, Catch themTime Limit:1000MSMemory Limit:10000KTotal Submissions:23915Accepted:7167DescriptionThe 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 Dragon and Gang Snake. However, the police first needs to identify whi
阅读全文
摘要:小希的迷宫Problem Description上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希望任意两个房间有且仅有一条路径可以相通(除非走了回头路)。小希现在把她的设计图给你,让你帮忙判断她的设计图是否符合她的设计思路。比如下面的例子,前两个是符合条件的,但是最后一个却有两种方法从5到达8。Input输入包含多组数据,每组数据是一个以0 0结
阅读全文
摘要:POJ 1308hdu 1325Is It A Tree?Time Limit:1000MSMemory Limit:10000KTotal Submissions:17384Accepted:5956DescriptionA tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following propert
阅读全文
摘要:食物链Time Limit:1000MSMemory Limit:10000KTotal Submissions:33805Accepted:9820Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述:第一种说法是"1 X Y",表示X和Y是同类。第二种说法是"2 X Y",表示X吃Y。此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句
阅读全文
摘要:Ubiquitous ReligionsTime Limit:5000MSMemory Limit:65536KTotal Submissions:19292Accepted:9472DescriptionThere are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university b
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232CSUST链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=19760#problem/C畅通工程Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19633Accepted Submission(s): 10103Problem Description某省调查城镇交通状况,得到现有
阅读全文
摘要:PS:第一道并查集题目Orz链接:http://acm.hdu.edu.cn/showproblem.php?pid=1878CSUST链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=10462#problem/A欧拉回路Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7271Accepted Submission(s): 2548Problem Description欧拉回路是
阅读全文
摘要:【转自】http://www.cnblogs.com/cherish_yimi/archive/2009/10/11/1580839.html文章作者:yx_th000文章来源:Cherish_yimi(http://www.cnblogs.com/cherish_yimi/) 转载请注明,谢谢合作。 [本文新址:http://www.ahathinking.com/archives/10.html]昨天和今天学习了并查集和trie树,并练习了三道入门题目,理解更为深刻,觉得有必要总结一下,这其中的内容定义之类的是取自网络,操作的说明解释及程序的注释部分为个人理解。并查集学习:l并查集:(un
阅读全文
摘要:原创链接:http://blog.163.com/zhaohai_1988/blog/static/209510085201263011135062/感谢作者,感谢kb神的推荐~~~~~~问题描述RMQ问题是求给定区间中的最值问题。对于长度为n的数列A,回答若干查询RMQ(A, i, j)。返回数组A中下标在[i,j]里的最小值的下标。比如数列 5,8,1,3,6,4,9,5,7 那么RMQ(2,4) = 3, RMQ(6,9) = 6.解决问题最简单的解法时间复杂度是O(n),就是对于每一个查询遍历一遍数组。但是当n非常大的时候,并且查询次数非常多的时候,这个解决方案就不是那么高效了。使..
阅读全文

浙公网安备 33010602011771号