How Many Answers Are Wrong(并查集)
Description
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)
Input
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.
Output
Sample Input
1 10 100
7 10 28
1 3 32
4 6 41
6 6 1
Sample Output
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- const int MAXN=200010;
- int F[MAXN];
- int val[MAXN];
- int find(int x)
- {
- if(F[x]==-1)return x;
- int tmp=find(F[x]);
- val[x]+=val[F[x]];
- return F[x]=tmp;
- }
- int main()
- {
- int n,m;
- int u,v,w;
- while(scanf("%d%d",&n,&m)==2)
- {
- memset(F,-1,sizeof(F));
- memset(val,0,sizeof(val));
- int ans=0;
- while(m--)
- {
- scanf("%d%d%d",&u,&v,&w);
- u=u-1;
- int t1=find(u);
- int t2=find(v);
- if(t1!=t2)
- {
- F[t2]=t1;
- val[t2]=val[u]-val[v]+w;
- }
- else
- {
- if(val[v]-val[u]!=w)ans++;
- }
- }
- printf("%d\n",ans);
- }
- return 0;
- }
How Many Answers Are Wrong(并查集)的更多相关文章
- 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 ...
- HDU 3038 How Many Answers Are Wrong (并查集)---并查集看不出来系列-1
Problem Description TT and FF are ... friends. Uh... very very good friends -________-bFF is a bad b ...
- HDU 3038 How Many Answers Are Wrong 并查集带权路径压缩
思路跟 LA 6187 完全一样. 我是乍一看没反应过来这是个并查集,知道之后就好做了. d[i]代表节点 i 到根节点的距离,即每次的sum. #include <cstdio> #in ...
- HDU3038 How Many Answers Are Wrong 并查集
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - HDU3038 题意概括 有一个序列,共n个数,可正可负. 现在有m个结论.n<=200000,m< ...
- 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 (带权并查集)
How Many Answers Are Wrong Problem Description TT and FF are ... friends. Uh... very very good frien ...
- 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 w ...
- 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 ...
- HDU 3038 How Many Answers Are Wrong 【YY && 带权并查集】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3038 How Many Answers Are Wrong Time Limit: 2000/1000 ...
随机推荐
- [LeetCode]题解(python):137-Single Number II
题目来源: https://leetcode.com/problems/single-number-ii/ 题意分析: 给定一个数组,数组里面每一个数字都出现了3次除了一个,找出那个数.要求时间复杂度 ...
- IOS 特定于设备的开发:监测Retina支持
近年来,Apple在其旗舰设备上引入了Retina显示屏.根据Apple的说法,他的像素密度非常高,足以使人眼无法区分单独的像素. UIScreen类提供了一种容易的方式,用于监查当前设备是否提供了内 ...
- 面试题之 query转为obj
要注意处理编码后的字串 对于a=123要得到number形的值 function parseQueryString(url) { var obj = {}; var query = url.sear ...
- MySQL mysqlimport 从txt文件中导入数据到mysql数据库
mysqlimport: 我说这个我们还是先从世界观方法论的高度来理解一下便有更加准确的把握.数据导入不外呼有两个部分 第一部分:目标对象--我们要把数据导给谁(mysqlimport 的目标对象自然 ...
- Linux 关机
1. shutdown shutdown -h now 立刻关机 shutdown -h 22:50 22:50 分的时候关机 shutdown -h +10 10分钟后关机 shutdwon -r ...
- Toolkit 一键激活Office 2010方法及Office 2010 Toolkit工具下载
Office 2010激活的方法很多,但推荐使用本站亲测,可永久使用的两种方法,随便使用哪一种,一个不行就换另外一个.基本上只要Office 2010正常安装了,下面两种方法的任何一种都可以正常激活. ...
- BingMap的GeocodeService进行地理位置正向和反向检索--后台实现
一.加入GeocodeService的Web服务引用 地理编码服务(GeocodeService)是以WCF技术公布的一个Web服务,地图编码服务提供了以一个有效的物理地址在地图上匹配其相应的地图地址 ...
- PID教程
PID教程 介绍 本教程将向您展示了比例每一个比例项 (P)的特点,积分项(I)和微分项 (D) 控制,以及怎样使用它们来获得所需的响应.在本教程中,我们会考虑下面单位反馈系统: Plant[被控对象 ...
- (译)Node.js的 EventEmitter 教程
原文标题:Node.js EventEmitter Tutorial 原文链接:http://www.hacksparrow.com/node-js-eventemitter-tutorial.htm ...
- 注册表:无法打开 XXX 由于某个错误无法打开该密钥。详细信息:拒绝访问
错误原因:没有注册表用户权限. 正确添加用户权限的步骤如下:(跟着图片步骤) 右击该项,权限: 选中想要添加为当前所有者的用户后,点击应用.如果没用户显示,可以从“其他用户或组”中添加进来. 权限添加 ...