How Many Answers Are Wrong

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 626 Accepted Submission(s): 283
 
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 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 1: Two integers, N and M (1 <= N <= 200000, 1 <= M <= 40000). Means TT wrote N integers and FF asked her M questions.

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
            A single line with a integer denotes how many answers are wrong.
 
Sample Input
10 5
1 10 100
7 10 28
1 3 32
4 6 41
6 6 1
 
Sample Output
1
 
 
Source
2009 Multi-University Training Contest 13 - Host by HIT
 
Recommend
gaojie
/*
A到B的和为W,可以理解为B比A大W,然后将AB加入并查集,如果B有父节点那么,B一定到某区间内的值就已经确定了,
在判断一下正不正确就可以了
*/
#include<bits/stdc++.h>
using namespace std;
int n,m;
int bin[];//用于构建并查集
int val[];//用于保存该节点到父节点的距离
int x,y,v;
int cur=;
int findx(int x)
{
int temp=x;
while(x!=bin[x])
{
val[temp]+=val[bin[x]];//将该节点到附加点的距离加起来
x=bin[x];
//cout<<"x="<<x<<endl;
}
bin[temp]=x;//路径压缩,将所有子孙节点都加到根节点下方
return x;
}
void inti()
{
for(int i=;i<=n;i++)
bin[i]=i,val[i]=;
cur=;
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
inti();
//cout<<n<<" "<<m<<endl;
for(int i=;i<m;i++)
{
scanf("%d%d%d",&x,&y,&v);
//cout<<x<<" "<<y<<" "<<v<<endl;
x-=;
int fx=findx(x);
int fy=findx(y);
//cout<<fx<<" "<<fy<<endl;
if(fx!=fy)
{
bin[fy]=fx;
val[fy]=val[x]-val[y]+v;
}
else
{
if(val[y]-val[x]!=v)
cur++;
}
}
printf("%d\n",cur);
}
return ;
}

How Many Answers Are Wrong的更多相关文章

  1. HDU3038 How Many Answers Are Wrong[带权并查集]

    How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  2. HDU 3038 How Many Answers Are Wrong(带权并查集)

    传送门 Description TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, ...

  3. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  4. linux下RTNETLINK answers: File exists的解决方案

    重启网卡时 出现 :RTNETLINK answers: File exists  提示 以下是网卡出来错误的解决方法: 第一种: 和 NetworkManager 服务有冲突,这个好解决,直接关闭 ...

  5. 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 ...

  6. 101+ Manual and Automation Software Testing Interview Questions and Answers

    101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...

  7. 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 ...

  8. UNIX command Questions Answers asked in Interview

    UNIX or Linux operating system has become default Server operating system and for whichever programm ...

  9. RTNETLINK answers: File exists错误

    解决ssh连接虚拟机出错,RTNETLINK answers: File exists 解决步骤如下: 使用ssh连接虚拟机的时候,发现目标主机无法连接,登录虚拟机,查看ssh监听是否开启: 发现监听 ...

  10. hdu 3038 How Many Answers Are Wrong

    http://acm.hdu.edu.cn/showproblem.php?pid=3038 How Many Answers Are Wrong Time Limit: 2000/1000 MS ( ...

随机推荐

  1. 杂谈--DML触发器学习

    触发器按类型分为三类: 1. DML 触发器,在数据变更时触发: 2. DDL 触发器,在修改数据库级别或实例级别对象时触发: 3. Login 触发器,在用户登录时触发: 最常见的是DML触发器,D ...

  2. sql语句增删改查与子查询

    修改表 修改表 语法: Alter table <旧表名> rename [ TO] <新表名>; 例子:Alter table `demo01` rename `demo02 ...

  3. WaitAll 和 WhenAll 的使用及区别

    用过.net 异步编程的同学都知道,比以前的多线程编程实现起来真的方便很多,今天把WaitAll和WhenAll这两种编程方式回顾总结一下(当然WaitAny.WhenAny是一样的操作) 1:Wai ...

  4. java集合系列——Map介绍(七)

    一.Map概述 0.前言 首先介绍Map集合,因为Set的实现类都是基于Map来实现的(如,HashSet是通过HashMap实现的,TreeSet是通过TreeMap实现的). 1:介绍 将键映射到 ...

  5. 【Spring】高级装配

    前言 前面讲解了bean的核心装配技术,其可应付很多中装配情况,但Spring提供了高级装配技术,以此实现更为高级的bean装配功能. 高级装配 配置profile bean 将所有不同bean定义放 ...

  6. uva11401

    题目大意:计算从1,2,3,...,n中选出3个不同的整数,使得以它们为边长可以构成三角形的个数. 思路:用一般的方法需要三重循环,时间复杂度为O(n^3),肯定超时,因此可用数学的方法对问题进行分析 ...

  7. 支持向量机(Support Vector Machine)-----SVM之SMO算法(转)

    此文转自两篇博文 有修改 序列最小优化算法(英语:Sequential minimal optimization, SMO)是一种用于解决支持向量机训练过程中所产生优化问题的算法.SMO由微软研究院的 ...

  8. Java高新技术 注解

      Java高新技术 注解 知识概要:                  (1)了解注解 (2)注解的应用结构图 (3)@Retention(RetentionPolicy.RUNTIME)    ...

  9. c# 反射得到实体类的字段名称和值,DataTable转List<T>

    /// <summary> /// 反射得到实体类的字段名称和值 /// var dict = GetProperties(model); /// </summary> /// ...

  10. c# 【MVC】WebApi通过HttpClient来调用Web Api接口

    /// <summary> /// HttpClient实现Post请求(异步) /// </summary> static async void dooPost() { st ...