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 墨染之樱 ...
随机推荐
- 杂项-ORM:LinqToSQL
ylbtech-杂项-ORM:LinqToSQL LINQ TO SQL 是包含在.NET Framework 3.5 版中的一种 O/RM 组件(对象关系映射),O/RM 允许你使用 .NET 的类 ...
- 关于UC、火狐、谷歌浏览器屏蔽布局中广告的解决办法
关于UC浏览器屏蔽了广西人才网的名企.品牌.热点的logo,是因为当成广告过滤掉了,以后div的class和id不能以“ad”开头.这可能只是其中一个规则,adxxxx是可以的,不能是adXxxx, ...
- SQL的三种连接方式内连接、左连接、外连接
1.内连接 select * from table_a x inner join table_b y on x.a_id = y.b_id 返回两个表关键字x.a_id = y.b_id的交集数据集 ...
- PreApplicationStartMethodAttribute的使用
先预备一个类,用于Start时调用 public static class MyPreApplicationStart { public static void RegisterGlobalFilte ...
- 生产者消费者模型(Queue,JoinableQueue)
生产者消费者模型 主要是为解耦 借助队列来实现生产者消费者模型 栈:先进后出(First In Last Out 简称 FILO) 队列: 先进先出(First In First Out 简称 FIF ...
- 高斯混合模型(理论+opencv实现)
查资料的时候看了一个不文明的事情,转载别人的东西而不标注出处,结果原创无人知晓,转载很多人评论~~标注了转载而不说出处这样的人有点可耻! 写在前面: Gaussian Mixture Model (G ...
- PHP写日志公共类
Txl_Log.php <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * * * ...
- 使用 intellij idea 进行远程调试
转自:http://yiminghe.iteye.com/blog/1027707 以前都是很土得打 log ,发现一篇关于 java 调试器架构 ,以及 eclipse 上使用 的文章,在常用的 i ...
- ldap快速配置
1.[yum lamp环境] yum -y install httpd httpd-devel mysql mysql-server mysql-devel php php-mysql php-co ...
- Python入门-散点图绘制
Python入门-散点图绘制 废话不说 直接上代码 import matplotlib.pyplot as plt x_values = list(range(1,1001)) y_values = ...