D. The Door Problem 带权并查集】的更多相关文章

http://codeforces.com/contest/776/problem/D 注意到每扇门都有两个东西和它连接着,那么,如果第i扇门的状态是1,也就是已经打开了,那么连接它的两个按钮的状态应该是一样的,也就是必须是同时按,或者同时不按.然后0的话就是关闭的,所以连接它的两个按钮应该是一个按,一个不按,或者相反. 所以这就是一个带权并查集(一开始没想到,以为相同的,用并查集合并就好,然后不同的,建立一个图什么的,发现有点麻烦,然后推着推着,就是带权并查集了),然后就写了很久很久,一直wa…
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…
题目: http://cojs.tk/cogs/problem/problem.php?pid=1070 1070. [焦作一中2012] 玻璃球游戏 ★   输入文件:marbles.in   输出文件:marbles.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 小x的业余生活中,有一项是玩滚玻璃球游戏. 某天,小x想到了一种很无趣的玩法,当然,这种玩法就是为了玩看题的你们. 小x首先建立了一个单向轨道,这个单向轨道可以抽象成一个有向图,每个顶点的出度都是1…
The Experience of Love Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) [Problem Description] A girl named Gorwin and a boy named Vivin is a couple. They arrived at a country named LOVE. The country consisting of N…
Exclusive-OR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 152 Accepted Submission(s): 55   Problem Description You are not given n non-negative integers X0, X1, ..., Xn-1 less than 220 , but th…
题目链接:http://poj.org/problem?id=1733 题目大意:有一个很长很长含有01的字符串,长度可达1000000000,首先告诉你字符串的长度n,再给一个m,表示给你m条信息,接下来的m行每行包含x,y,even/odd,表示区间[x,y]中1的个数,even为偶数,odd为奇数.判断前几条是对的,也就是说假设k+1条信息与前面相互矛盾,就输出k,说明前k条正确. 例:Sample Input 1051 2 even3 4 odd5 6 even1 6 even7 10…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3376 题目大意: 编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱. 有P(1≤P≤100000)个指令.指令有两种: 1.移动(M):将包含X的立方柱移动到包含Y的立方柱上. 2.统计(C):统计名含X的立方柱中,在X下方的方块数目. 题解: 带权并查集 存三个东西,x所在立方柱的最顶端fa[x],x所在立方柱的最底端d[x],x上面有多少个立方柱f[x](下…
题目链接:https://zhixincode.com/contest/14/problem/I?problem_id=211 样例输入 1  3 5 2 1 1 2 1 2 1 1 2 3 2 1 样例输出 1 27 9 6 题解: 首先,比较明显地是,每进行一次操作 $1$,对于目前的卡牌分配情况的种数,其中的 $1/3$ 种是被撤掉位子的人留下,其余 $2/3$ 种是“擂主”留下. 而且,进行完一次操作 $1$ 后,“擂主”位子上分配到的卡牌,石头剪刀布的数目比依然是均等的,因此不会影响后…
http://hihocoder.com/problemset/problem/1515 题意: 思路: 带权并查集的简单题,计算的时候利用向量法则即可. #include<iostream> #include<cstdio> using namespace std; +; int n,m,q; int p[maxn],r[maxn]; int finds(int x) { if(p[x]==x) return x; int tmp = p[x]; p[x] = finds(p[x…