How Many Answers Are Wrong(带权并查集)
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
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).
Then, FF can choose a continuous subsequence from it(for example the subsequence from the third to the fifth integer inclusively). After that, FF will ask TT what the sum of the subsequence he chose is. The next, TT will answer FF's question. Then, FF can redo this process. In the end, FF must work out the entire sequence of integers.
Boring~~Boring~~a very very boring game!!! TT doesn't want to play with FF at all. To punish FF, she often tells FF the wrong answers on purpose.
The bad boy is not a fool man. FF detects some answers are incompatible. Of course, these contradictions make it difficult to calculate the sequence.
However, TT is a nice and lovely girl. She doesn't have the heart to be hard on FF. To save time, she guarantees that the answers are all right if there is no logical mistakes indeed.
What's more, if FF finds an answer to be wrong, he will ignore it when judging next answers.
But there will be so many questions that poor FF can't make sure whether the current answer is right or wrong in a moment. So he decides to write a program to help him with this matter. The program will receive a series of questions from FF together with the answers FF has received from TT. The aim of this program is to find how many answers are wrong. Only by ignoring the wrong answers can FF work out the entire sequence of integers. Poor FF has no time to do this job. And now he is asking for your help~(Why asking trouble for himself~~Bad boy)
Line 2..M+1: Line i+1 contains three integer: Ai, Bi and Si. Means TT answered FF that the sum from Ai to Bi is Si. It's guaranteed that 0 < Ai <= Bi <= N.
You can assume that any sum of subsequence is fit in 32-bit integer.
参考博客:https://blog.csdn.net/Dextrad_ihacker/article/details/51016017
#include <iostream>
using namespace std;
#define maxn 200005 int fa[maxn],sum[maxn]; void init(int n){
for(int i=;i<=n;i++){
sum[i]=;
fa[i]=i;
}
} int Find(int x){
if(x==fa[x]) return x;
int tmp=fa[x];
fa[x]=Find(fa[x]);
sum[x]+=sum[tmp];
return fa[x];
} bool Join(int x,int y,int v){
int xx=Find(x);
int yy=Find(y);
if(xx==yy){
if(sum[x]+v!=sum[y]) return false;
return true;
}
fa[yy]=xx;
sum[yy]=sum[x]+v-sum[y];
return true;
} int main(){ int n,m;
while(cin>>n>>m){
init(n+);
int L,R,v;
int ans=;
while(m--){
cin>>L>>R>>v;
if(!Join(L-,R,v)){
ans++;
}
}
cout<<ans<<endl;
} }
How Many Answers Are Wrong(带权并查集)的更多相关文章
- HDU3038 How Many Answers Are Wrong —— 带权并查集
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3038 How Many Answers Are Wrong Time Limit: 200 ...
- hdu3038How Many Answers Are Wrong(带权并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题解转载自:https://www.cnblogs.com/liyinggang/p/53270 ...
- HDU3038 How Many Answers Are Wrong[带权并查集]
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 【HDU3038】How Many Answers Are Wrong - 带权并查集
描述 TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always ...
- hdu 3038 How Many Answers Are Wrong ( 带 权 并 查 集 )
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU3038:How Many Answers Are Wrong(带权并查集)
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU 3038 How Many Answers Are Wrong(带权并查集)
太坑人了啊,读入数据a,b,s的时候,我刚开始s用的%lld,给我WA. 实在找不到错误啊,后来不知怎么地突然有个想法,改成%I64d,竟然AC了 思路:我建立一个sum数组,设i的父亲为fa,sum ...
- HDU 3038 - How Many Answers Are Wrong - [经典带权并查集]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- 【带权并查集】【HDU3038】【How Many Answers Are Wrong】d s
这个题看了2天!!!最后看到这篇题解才有所明悟 转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298091.html ---by 墨染之樱 ...
随机推荐
- CMake Error: Curses library not found. Please install appropriate package
编译安装MySQL的时候,出现错误: -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Err ...
- jquery粘贴操作
今天忘记记录一个点了,关于input字体默认浅色,聚焦变深的问题. 图一,默认浅色 图二,聚焦出现下拉框“最近搜索”记录,点击“程序员” 图三,input值变为“程序员”,颜色没有变深(复制粘贴也不变 ...
- [UE4]组件
用来组成Actor的子对象,Actor是由组件组成的. 几个关键的Component类型: 一.UActorComponent 这个Component的基类,可以被放到Actor里面, 可以接受Tic ...
- linux查看某个目录下有哪些文件的命令
分别是ll和ls命令 ll /usr/local/lib ls /usr/local/lib
- seaborn分类数据可视化
转载:https://cloud.tencent.com/developer/article/1178368 seaborn针对分类型的数据有专门的可视化函数,这些函数可大致分为三种: 分类数据散点图 ...
- OpenGL 画出雷达动态扫描效果(一)
最终效果如下所示 Demo下载 http://files.cnblogs.com/xd-jinjian/Debug.zip 源代码下载 http://download.csdn.net/detail ...
- 使用SolrNet访问Solr-5.5.0
由于今年年初刚发布的Solr-5.5.0,网上所能找到的资料少之又少,所以只能靠自己一点点摸索. 从某Hub上下载了SolrNet源码,按照教程提交文档或者查询均失败,无奈只得跟断点一点点差怎么回事. ...
- js判断当前为pc端还是wap端
var checkBrowser; function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); v ...
- WebLogic 任意文件上传 远程代码执行漏洞 (CVE-2018-2894)------->>>任意文件上传检测POC
前言: Oracle官方发布了7月份的关键补丁更新CPU(Critical Patch Update),其中针对可造成远程代码执行的高危漏洞 CVE-2018-2894 进行修复: http://ww ...
- c++官方文档-命名空间
#include<stdio.h> #include<iostream> #include<queue> #include<map> #include& ...