HDU 3038】的更多相关文章

1.POJ 1733 Parity game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5744   Accepted: 2233 Description Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You cho…
http://acm.hdu.edu.cn/showproblem.php?pid=3038 题意:[1-n]的区间,有m个询问,每个询问表示[a,b]的和是s,问一共有多少组矛盾 sum[i]表示i到根节点的和,求区间和用sum[b]-sum[a-1] 为方便描述先把a-- 我是把b的父亲接在a的父亲上,下面图都是如此 1.当b和a在同一个集合,只需判断[a,b]间和是否是s,算法用向量表示,如下图 if(sum[b]-sum[a]!=s)ans++; 2.a.b不在同一个集合,把b的父亲连在…
http://acm.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): 3648 Accepted Submission(s): 1401 Problem Description TT and FF are ... fri…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题意:给出区间[1,n],下面有m组数据,l r v区间[l,r]之和为v,每输入一组数据,判断此组条件是否与前面冲突 ,最后输出与前面冲突的数据的个数.比如 [1 5]区间和为100 然后后面给出区间[1,2]的和为 200 那肯定就是有问题的了. 极力推荐这位大牛的博客:http://blog.csdn.net/niushuai666/article/details/6981689 这题让…
题目链接: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…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=3038 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/D 代码: #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<algorithm> #includ…
任意门:http://acm.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): 15582    Accepted Submission(s): 5462 Problem Description TT and FF…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题意:就是给出n个数和依次m个问题,每个问题都是一个区间的和,然后问你这些问题中有几个有问题,有问题的直接忽略. 每个问题给出a-b之间的和为s,其实就是val(b)-val(a-1)的值为s,这样就容易想到用向量的方法来求解 #include <iostream> #include <cstring> #include <cmath> #include <cs…
题目链接 食物链类似的题,主要是在于转化,a-b的和为s,转换为b比a-1大s.然后并查集存 此节点到根的差. 假如x的根为a,y的根为b: b - y = rank[y] a - x = rank[x] y - x = s 可以推出b - a = rank[y] - rank[x] + s; 并查集 延迟更新什么的,都忘了啊. 还有这题,如果是x--的话,记得更新0的根. #include <cstring> #include <cstdio> #include <stri…
传送门 Description 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-_…
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 -_____…
加权并查集 似乎就是在想这题的时候突然理解了之前看E题没看懂的标准加权解法 值得注意的技巧 为了让区间之前连成树 形式设定为为(l, r] 接受l的输入后先自减一下就可以了 #include <iostream> #include <string> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <map> #i…
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3404    Accepted Submission(s): 1310 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…
思路跟 LA 6187 完全一样. 我是乍一看没反应过来这是个并查集,知道之后就好做了. d[i]代表节点 i 到根节点的距离,即每次的sum. #include <cstdio> #include <cstring> #include <cstdlib> ; int N, Q; int p[MAXN]; int d[MAXN]; int FindSet( int x ) { if ( p[x] == x ) return x; int root = FindSet(…
了解了种类并查集,同时还知道了一个小技巧,这道题就比较容易了. 其实这是我碰到的第一道种类并查集,实在不会,只好看着别人的代码写.最后半懂不懂的写完了.然后又和别人的代码进行比较,还是不懂,但还是交了. 现在回过头来看,又看了一遍. 题意—— 输入—— 给出多组测试数据. 每组数据第一行包含两个整数n, m.n表示共有1——n这么多个数,m表示m组提示. 接下来m行,每行包含三个整数a, b, val.表示从a到b这几个数的和为val. 这几组数有可能有冲突,问一共有多少组有冲突的数据. 输出—…
How Many Answers Are Wrong Problem Description TT and FF are ... friends. Uh... very very good friends -________-bFF 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…
总算碰到一道不那么无聊的题了^^ 先说一下题意吧,有两个人一个叫TT的男孩一个叫FF的女孩(名字太随意了吧....),这个叫TT的男孩会经常叫这个女孩一起玩一个游戏,这个有些是这样的,随便写一个数列,现在TT会选择一个区间,然后让FF计算这个区间里面所有数的和,这是一个非常非常无聊的游戏,于是FF准备捉弄一下TT,有时候她会故意计算出来一个错的答案,当然TT也比较聪明,他会发现这个答案跟以前的答案会有冲突,那么问题来了,有多少话是假的呢??? //////////////////////////…
Problem Description TT and FF are ... friends. Uh... very very good friends -________-bFF 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 integer…
题目大意:TT 和 FF玩游戏(名字就值五毛),有一个数列,数列有N个元素,现在给出一系列个区间和该区间内各个元素的和,如果后出现的一行数据和前面一出现的数据有矛盾,则记录下来.求有矛盾数据的数量. 题目思路:刚刚拿到手时一脸懵逼,这是并查集?后来发现还真是并查集 - -!! 如果数据有错那么会是什么情况? 1-10 10 1-5   5 6-10  4 很明显第三行的数据和已知的数据产生了矛盾,我们分析一下矛盾是如何产生的. 我们用v[i]来统计最右端为i的区间和,那么: 第一行数据得知v[1…
思路:种类并查集的每个节点应该保存它的父节点以及他和父节点之间的关系.假设root表示根结点,sum[i-1]表示i到根结点的和,那么sum[j-1] - sum[i]可以得到区间[j, i]的和.那么给定(x, y, real)可以看作x-1到节点y的和为real AC代码 #include <cstdio> #include <cmath> #include <cctype> #include <algorithm> #include <cstri…
参考博客 How Many Answers Are Wrong Problem Description 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…
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14546    Accepted Submission(s): 5125 Problem Description TT and FF are ... friends. Uh... very very good friends -____…
题意:给出多个区间的和,判断数据矛盾的区间有几个,比方说[1,5] = 10 ,[6.10]  = 10, [1, 10] = 30,这明显第三个与前面两个矛盾. 链接:点我 水题了,val代表到根的和 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<…
这道题我拖了有8个月... 今天放假拉出来研究一下带权的正确性,还有半开半闭的处理还有ab指向的一系列细节问题 #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; const int maxn = 200010; int p[maxn],r[maxn]; void init(int n){ memset(r,0,sizeo…
题意: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…
#include<stdio.h> #include<string.h> #define N  200100 struct node { int x,count; }pre[N]; int find(int n) { if(n!=pre[n].x) { int h=pre[n].x; pre[n].x=find(pre[n].x); pre[n].count=pre[n].count+pre[h].count; } return pre[n].x; } int Union(int…
题目链接 并查集是用来对集合合并查询的一种数据结构,或者判断是不是一个集合,本题是给你一系列区间和,判断给出的区间中有几个是不合法的. 思考: 1.如何建立区间之间的联系 2.如何发现悖论 首先是如何建立联系,我们可以用一张图表示 假如说区间[fx,x]是之前建立的区间,他们之间和为sum[x],fx和x的联系可以用集合来存储,同理[fy,y]也是如此.当给出了一个新的区间[x,y]时,且区间和为s. 就产生了两种情况了,如果fx == fy 那么这两个区间是有关联的区间,也就是[x,y]之间的…
#include<iostream> #include<cstring> using namespace std; ; int d[N],p[N]; int find(int x) { if(p[x]!=x) { int root=find(p[x]); d[x]+=d[p[x]]; p[x]=root; } return p[x]; } int main() { int n,m,a,b,sum; while(cin>>n>>m) { ;i<=n;i+…