How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2961    Accepted Submission(s): 1149 Problem Description TT and FF are ... friends. Uh... very very good friends -_____…
太坑人了啊,读入数据a,b,s的时候,我刚开始s用的%lld,给我WA. 实在找不到错误啊,后来不知怎么地突然有个想法,改成%I64d,竟然AC了 思路:我建立一个sum数组,设i的父亲为fa,sum[i]表示(fa,i]中的数的和(不包括fa,包括i), 合并的时候,不是合并a,b,而是合并a-1,b.这样做的目是因为s是[a,b]的和,如果直接合并a,b,那么按照我数组的定义应该是(a,b]的和,这样不符合题意. 接下来,每次读入a,b,只要根据他们父节点的不同情况分类讨论即可. #incl…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3038 How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10164    Accepted Submission(s): 3699 Problem Description TT…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题解转载自:https://www.cnblogs.com/liyinggang/p/5327055.html 题目大意:有n个数,你不知道具体是啥,只知道有n个,然后输入m组数据,每组包含三个整数,a,b,s,表示区间[a,b]的整数和为s,输出有错误的数据的组数. 解题思路:是个典型的带权并查集,难点就在于更新相对信息值.在查找和合并也要对相对信息值进行更新. 做法是用一个数组存储某个节点…
Background Professor 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. In his experiment, individual bugs and their in…
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6336    Accepted Submission(s): 2391 Problem Description TT and FF are ... friends. Uh... very very good friends -_____…
描述 TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin with, TT should write down a sequence of integers-_-!!(bored). T…
了解了种类并查集,同时还知道了一个小技巧,这道题就比较容易了. 其实这是我碰到的第一道种类并查集,实在不会,只好看着别人的代码写.最后半懂不懂的写完了.然后又和别人的代码进行比较,还是不懂,但还是交了. 现在回过头来看,又看了一遍. 题意—— 输入—— 给出多组测试数据. 每组数据第一行包含两个整数n, m.n表示共有1——n这么多个数,m表示m组提示. 接下来m行,每行包含三个整数a, b, val.表示从a到b这几个数的和为val. 这几组数有可能有冲突,问一共有多少组有冲突的数据. 输出—…
How Many Answers Are Wrong http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16222    Accepted Submission(s): 5692 Problem Description TT and FF are…
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16338    Accepted Submission(s): 5724 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Description: TT and FF are ..…
Virtual Friends Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11092    Accepted Submission(s): 3221 Problem Description These days, you can do all sorts of things online. For example, you can…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always…
题意:n个数,m次询问,每次问区间a到b之间的和为s,问有几次冲突 思路:带权并查集的应用.[a, b]和为s,所以a-1与b就能够确定一次关系.通过计算与根的距离能够推断出询问的正确性 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 200010; int f[MAXN],a…
带权并查集,设f[x]为x的父亲,s[x]为sum[x]-sum[fx],路径压缩的时候记得改s #include<iostream> #include<cstdio> using namespace std; const int N=200005; int n,m,s[N],f[N],ans; int read() { int r=0,f=1; char p=getchar(); while(p>'9'||p<'0') { if(p=='-') f=-1; p=get…
题目链接 并查集是用来对集合合并查询的一种数据结构,或者判断是不是一个集合,本题是给你一系列区间和,判断给出的区间中有几个是不合法的. 思考: 1.如何建立区间之间的联系 2.如何发现悖论 首先是如何建立联系,我们可以用一张图表示 假如说区间[fx,x]是之前建立的区间,他们之间和为sum[x],fx和x的联系可以用集合来存储,同理[fy,y]也是如此.当给出了一个新的区间[x,y]时,且区间和为s. 就产生了两种情况了,如果fx == fy 那么这两个区间是有关联的区间,也就是[x,y]之间的…
这个题看了2天!!!最后看到这篇题解才有所明悟 转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298091.html   ---by 墨染之樱花 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题目描述:某个无聊的骚年给他的女友(烧!)一系列三元组x,y,c,表示序列中ax+ax+1+...+ay=c.但是其中有一些是错误的,也就是与前面的信息出现了冲突,比如给了1,2,6和3,4,…
http://acm.hdu.edu.cn/showproblem.php?pid=3038 大致题意: 有一个区间[0,n],然后会给出你m个区间和,每次给出a,b,v,表示区间[a,b]的区间和为v,但每次给出的区间可能与之前的有冲突,问这样起冲突的区间共有多少个 首先区间[a,b]的和可由区间[0,b]的和减去区间[0,a-1]的和得到 但是我们不太可能知道[0,b],故我们只用知道和b的合并过的区间的左端点就行 其实并查集实质就是一颗树,我们可以以树的角度去看待它,理解维护过程 不理解的…
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…
http://acm.hdu.edu.cn/showproblem.php?pid=3047 题意: 给出n个座位,有m次询问,每次a,b,d表示b要在a右边d个位置处,问有几个询问是错误的. 思路: 基础带权并查集. #include<iostream> #include<cstdio> using namespace std; +; int n,m; int p[maxn],r[maxn]; int finds(int x) { if(p[x]==x) return x; in…
传送门 The Experience of Love Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 91 Problem Description A girl named Gorwin and a boy named Vivin is a couple. They arriv…
http://acm.hdu.edu.cn/showproblem.php?pid=3047 [题意] http://blog.csdn.net/hj1107402232/article/details/9921311 [Accepted] #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algor…
Zjnu Stadium 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3047 Problem Description In 12th Zhejiang College Students Games 2007, there was a new stadium built in Zhejiang Normal University. It was a modern stadium which could hold thousands of peop…
题意:Bug有两种性别,异性之间才交往, 让你根据数据判断是否存在同性恋,输入有 t 组数据,每组数据给出bug数量n, 和关系数m, 以下m行给出相交往的一对Bug编号 a, b.只需要判断有没有,按题目要求输出.这题有点坑的地方在于输出上多了一行空行,不PE都没注意到. 思路: 用一个数组gender[i] 记录当前节点 i 与根节点的关系,parent[i]数组记录当前节点的父节点. 因为是带权并查集,在Find_Parent 时更新当前节点与根节点的关系,且路径压缩至根节点下, 所以不用…
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…
思路: 带权并查集+向量偏移 #include <iostream> using namespace std; int n, m; ]; ]; // 到根节点的距离 ; void init() { ; i <= n; i++) { pre[i] = i; f[i] = ; } } int Find(int x) { if (x == pre[x]) return x; int y = pre[x]; pre[x] = Find(pre[x]); f[x] += f[y]; return…
A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8528    Accepted Submission(s): 2745 Problem Description Background  Professor Hopper is researching the sexual behavior of a rare…
题目 带权并查集的博客~ 题目: 多组输入数据.n,m.你不知道[1,n]内任意区间内值的和. m次询问,a b 是端点,都在n的范围以内 : v表示 [a,b]的区间内值的和.对每次询问,判断v是否与前面询问冲突,不冲突就当做是真的. 思路: 看上面的博客~ #include<iostream> #include<cstdio> #include <cctype> #include<algorithm> #include<cstring> #i…
Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3179 Accepted Submission(s): 1224 Problem Description In 12th Zhejiang College Students Games 2007, there was a new stadium built in Zh…
题意: 一圈座位有n个,给出m组序号之间的关系,比如,1 2 150 代表2号坐在1号位置序号+150,看m组数据有多少组冲突的. 思路: 带权并查集模板. #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<queue> #include<vector> #include<stdlib.h> using…
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=3038 题意: n表示有一个长度为n的数组, 接下来有m行形如x, y, d的输入, 表示从第x,个元素到第y个元素的和为d(包括x, 和y), 问m行输入里面有几个是错误的(第一个输入是正确的); 思路: 很显然带权并查集咯,我们可以用距离的概念代替和的概念比较好理解一点,d表示x到y的和即x到y的距离; 可以用rank[x]表示x到其父亲节点的距离,  将正确的距离关系合并到并查集中…