hdu 3038 给区间和,算出多少是错的
How Many Answers Are Wrong
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.
1 10 100
7 10 28
1 3 32
4 6 41
6 6 1
思路:
总结:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int boss[],sum[];
int fin(int x)
{
if(boss[x]==x)return x;
int fx=boss[x];
boss[x]=fin(boss[x]);
sum[x]+=sum[fx];
return boss[x];
}
int main()
{
int n,m,a,b,c,fa,fb,ans=;
while(cin>>n>>m)
{ans=;
for(int i=;i<=n;i++)boss[i]=i,sum[i]=;//初始化boss与sum
for(int i=;i<m;i++)
{
scanf("%d %d %d",&a,&b,&c);
fa=fin(a-);fb=fin(b);//寻找根,并且更新sum值
if(fa==fb)
{
if(sum[a-]-sum[b]!=c)ans++;//a-1与b之间有(a,a+1,a+2...b)
}
else
{
boss[fa]=fb;
sum[fa]=-sum[a-]+sum[b]+c;
}
}
cout<<ans<<endl;
}
return ;
}
hdu 3038 给区间和,算出多少是错的的更多相关文章
- 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733
1.POJ 1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5744 Accepted: ...
- HDU 5726 GCD 区间GCD=k的个数
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- hdu 3038 How Many Answers Are Wrong(并查集的思想利用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题意:就是给出n个数和依次m个问题,每个问题都是一个区间的和,然后问你这些问题中有几个有问题,有 ...
- HDU 3038 How Many Answers Are Wrong(带权并查集)
传送门 Description TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, ...
- 一次 Oracle 算出运算溢出问题 排查解决 (并非除数为零!)
前段时间 出现过这个问题,: 表中有一列为number类型 rec_recordlength (两个时间的间隔长度/秒) 部分数据 统计这个字段就会出现 "算出运算溢出" 错误,很 ...
- javascript基础程序(算出一个数的平方值、算出一个数的阶乘、输出!- !- !- !- !- -! -! -! -! -! 、函数三个数中的最大数)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 关于一道面试题【字符串 '1 + (5 - 2) * 3',怎么算出结果为10,'eval'除外】
最近徘徊在找工作和继续留任的纠结之中,在朋友的怂恿下去参加了一次面试,最后一道题目是: 写一个函数,输入一个字符串的运算式,返回计算之后的结果.例如这样的: '1 + (5 - 2) * 3',计算出 ...
- [转]JAVA 根据经纬度算出附近的正方形的四个角的经纬度
csv文件转化为geojson文件中,涉及到路测图的打点生成,打点是由一个个正方形组成,而正方形是由四个点组成的,这四个点根据经纬度和范围生成,具体的实现代码是从网上找来的: /** * * @par ...
- JavaScript如何根据当天算出前三天和后三天
经杨秀徐批准 中央军委颁发意见建设新型司令机关news 杨秀徐会见到北京述职的香港特首梁振英news 海军372潜艇官兵先进事迹报告会举行 杨秀徐作指示news 中央农村工作会议在京召开 李克强作重要 ...
随机推荐
- 关于数据库不适合docker的原因(摘抄)
所有的服务都开始了容器化升级,在一切皆容器的主流思想下,无状态的服务采用容器化已经是大势所趋,常常困扰架构师的一个问题是,数据库是否需要容器化? 数据库不适合容器化的七大原因 1. 数据不安全 即使你 ...
- zk理解(转载自邬兴亮---www.cnblogs.com/wuxl360/p/5817471.html)
一.分布式协调技术 在给大家介绍ZooKeeper之前先来给大家介绍一种技术——分布式协调技术.那么什么是分布式协调技术?那么我来告诉大家,其实分布式协调技术 主要用来解决分布式环境当中多个进程之间的 ...
- 零基础掌握百度地图兴趣点获取POI爬虫(python语言爬取)(代码篇)
好,现在进入高阶代码篇. 目的: 爬取昆明市中学的兴趣点POI. 关键词:中学 已有ak:9s5GSYZsWbMaFU8Ps2V2VWvDlDlqGaaO 昆明市坐标范围: 左下角:24.390894 ...
- File类_常见的方法(获取目录中指定规则的内容)
首先定义过滤器 import java.io.File; import java.io.FilenameFilter; public class FileByJava implements Filen ...
- android:layout_margin真实含义 及 自己定义复合控件 layout()运行无效的问题解决
一.关于layout_margin 搞Android时间也不短了.对layout_margin也不陌生了,可近期遇到一个问题让我发现,对它的认识还不够深入全面.大量网络资料上都说,layout_mar ...
- 一个非常好的php实现手机号归属地查询接口类
前一阵子看到了一个非常好的php手机归属地查询的类,写的很精简,查询也很精确!大致代码是这样的: <?php header("Content-type:text/html;charse ...
- yii2 修改验证码小部件样式
<?= $form->field($model, 'verifyCode',['labelOptions' => ['class' => 'yanzhengma','style ...
- Qt 编程指南 1 从Hello World开始
1 简单的hello QT 注意项目和路径不要包含任何中文字符,特殊字符,空格. 只能有英文,数字,下划线,且不能数字开头. //helloqt.cpp #include <QtWidgets/ ...
- go标准库的学习-sync互斥
https://studygolang.com/pkgdoc 导入方法: import "sync" sync包提供了基本的同步基元,如互斥锁.除了Once和WaitGroup类型 ...
- mac版本idea使用(二)-如何安装PlantUML画时序图、类图
在跟踪spring源码的时候,看见网上的博客好多使用了idea自带的展示类继承关系图的功能,这个地方使用了idea的diagrams-show diagram,就可以显示类的继承图,很神奇的样子,记录 ...