HDU3038:How Many Answers Are Wrong(带权并查集)
How Many Answers Are Wrong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16338 Accepted Submission(s): 5724
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038
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
题解:
这题干......直接看我写的另一份题解吧:https://www.cnblogs.com/heyuhhh/p/9977617.html
代码也差不多的,注意这是多组数据!!如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std; typedef long long ll;
const int N = ;
ll f[N],sum[N];
int t,n,m; int find(int x){
if(f[x]==x) return x;
int tmp = f[x];
f[x]=find(f[x]);
sum[x]+=sum[tmp];
return f[x];
} int main(){
while(~scanf("%d%d",&n,&m)){
memset(sum,,sizeof(sum));
for(int i=;i<=n+;i++) f[i]=i;
int ans = ;
for(int i=,x,y,w;i<=m;i++){
scanf("%d%d%d",&x,&y,&w);y++;
int fx = find(x),fy=find(y);
if(fx==fy){
if(sum[y]-sum[x]!=w) ans++;
}else{
f[fy]=fx;
sum[fy]=sum[x]-sum[y]+w;
}
}
printf("%d\n",ans);
}
return ;
}
HDU3038: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 ...
- HDU3038 How Many Answers Are Wrong[带权并查集]
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 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 - 带权并查集
描述 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 ...
- How Many Answers Are Wrong(带权并查集)
How Many Answers Are Wrong http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS ( ...
- HDU 3038 How Many Answers Are Wrong(带权并查集)
太坑人了啊,读入数据a,b,s的时候,我刚开始s用的%lld,给我WA. 实在找不到错误啊,后来不知怎么地突然有个想法,改成%I64d,竟然AC了 思路:我建立一个sum数组,设i的父亲为fa,sum ...
- 【带权并查集】【HDU3038】【How Many Answers Are Wrong】d s
这个题看了2天!!!最后看到这篇题解才有所明悟 转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298091.html ---by 墨染之樱 ...
- HDU-3038 How Many Answers Are Wrong(带权并查集区间合并)
http://acm.hdu.edu.cn/showproblem.php?pid=3038 大致题意: 有一个区间[0,n],然后会给出你m个区间和,每次给出a,b,v,表示区间[a,b]的区间和为 ...
随机推荐
- FPGA算法学习(1) -- Cordic(圆周系统之旋转模式)
三角函数的计算是个复杂的主题,有计算机之前,人们通常通过查找三角函数表来计算任意角度的三角函数的值.这种表格在人们刚刚产生三角函数的概念的时候就已经有了,它们通常是通过从已知值(比如sin(π/2)= ...
- Microsoft Security Essentials 和 Windows Defender 离线升级包下载地址
自从微软提供了免费的杀毒软件之后我就卸载掉了其他的杀毒软件.但是最近遇到了个小问题,我这里有一批电脑不能联网,杀毒软件的升级成了问题.在网上搜索了一番,终于找到了官方的离线升级包下载地址.放在这里备用 ...
- Hibernate-ORM:15.Hibernate中的Criteria查询
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客讲师Hibernate中的Criteria查询! 一,Criteria简介: 刚接触Hibernate ...
- 最小总代价 状压DP
描述 n个人在做传递物品的游戏,编号为1-n. 游戏规则是这样的:开始时物品可以在任意一人手上,他可把物品传递给其他人中的任意一位:下一个人可以传递给未接过物品的任意一人. 即物品只能经过同一个人一次 ...
- jmeter接口测试--响应结果Unicode转码成中文
jmeter接口测试-响应结果Unicode转码成中文 一般情况下,接口返回数据都会经过加密,所以有时相应结果会显示为Unicode,因此,需添加BeanShell PostProcessor,加入代 ...
- MySQL训练营02
一.表操作: 1.MySQL表的数据类型: MySQL的数据类型分为3种: 数值 时间/日期 字符/字符串 (1)数值类型: 包括:TinyInt.SmallInt.MediumInt.Int.Big ...
- Flask 学习笔记(二):RESTful API
概括 URL:需要操作的对象,也就是资源 HTTP method:我要对该对象做什么(POST 增.DELETE 删.GET 查.PUT 和 PATCH 改) HTTP status code:操作的 ...
- linux备忘录-账号管理与ACL权限设定
知识 账号管理中的一些文件结构 /etc/passwd 每一行的内容都为下面结构 账号名称:密码:UID:GID:用户信息说明:家目录:shell ---- UID ---- -- 0 -> 代 ...
- 软工实践Beta冲刺(3/7)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...
- Alpha冲刺(7/10
团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 学会了POSTMAN的使用,对后端已经完成的接口进行了收发消息正确性的验证 推 ...