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 (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3648 Accepted Submission(s):
1401
-________-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.
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.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#define N 200010 int f[N], r[N]; int Find(int x)
{
int k = f[x];
if(x != f[x])
f[x] = Find(f[x]);
r[x] = r[x] + r[k];
return f[x];
} int main()
{
int i, n, m, x, y, w, rx, ry, ans;
while(scanf("%d%d", &n, &m) != EOF)
{
ans = ;
for(i = ; i <= n ; i++)
{
f[i] = i;
r[i] = ;
}
while(m)
{
m--;
scanf("%d%d%d", &x, &y, &w);
x--;
rx = Find(x), ry = Find(y);
if(rx != ry)
{
f[ry] = rx;
r[ry] = w + r[x] - r[y];
}
else
{
if(w != r[y] - r[x])
ans++;
}
}
printf("%d\n", ans);
}
return ;
}
hdu 3038 How Many Answers Are Wrong的更多相关文章
- 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 ...
- 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(并查集的思想利用)
题目链接: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, ...
- 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 (并查集)
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(带权并查集,真的很难想到是个并查集!!!)
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,转换为b比a-1大s.然后并查集存 此节点到根的差. 假如x的根为a,y的根为b: b - y = rank[y] a - x = rank[ ...
随机推荐
- 关于 Memcached 的一些使用
关于Memcached的一些用法, Memcached 在Windows下的版本费了很大劲,才找到.win32,win64都有.本来想自己build的,但是Cygwin下载包也是费老劲了,下不下来. ...
- Ubuntu下jdk配置
在Oracle官网下载linux版本的以tar.gz结尾的jdk建立文件夹用来存放解压后的jdksudo mkdir /usr/java进入jdk下载文件夹,解压并存放jdksudo tar zxvf ...
- 宏HASH_GET_NEXT
/*******************************************************************//** Gets the next struct in a h ...
- JSOI2008最大数(线段树)
注意到数列只增不减,而题目中又明确说道m<=200000;这样的数据规模线段树完全可以承受得了.所以我们可以事先建好一棵200000个子节点的线段树,然后求极值就好了. type node=re ...
- mysql 分页存储过程 一次返回两个记录集(行的条数,以及行记录),DataReader的Read方法和NextResult方法
DELIMITER $$ USE `netschool`$$ DROP PROCEDURE IF EXISTS `fn_jk_GetCourses`$$ CREATE DEFINER=`root`@` ...
- UVA 10765 Doves and bombs(双连通分量)
题意:在一个无向连通图上,求任意删除一个点,余下连通块的个数. 对于一个非割顶的点,删除之后,原图仍连通,即余下连通块个数为1:对于割顶,余下连通块个数>=2. 由于是用dfs查找双连通分量,树 ...
- [Sciter系列] MFC下的Sciter–3.Sciter脚本与底层交互
[Sciter系列] MFC下的Sciter–3.Sciter脚本与底层交互,脚本调用底层自定义的方法函数. 本系列文章的目的就是一步步构建出一个功能可用,接口基本完善的基于MFC框架的SciterF ...
- POI读取Word与Excel
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; ...
- Android:真机调试,不显示logcat的解决方案
有时做开发的时候,用真机测试,总是看不到logcat信息 .原因是系统默认关闭了log,需要将其打开. 解决办法如下: 在拨号界面输入*#*#2846579#*#* ,然后系统会自动弹出一个菜单, ...
- Oracle RAC环境下如何更新patch(Rolling Patch)
Oracle RAC数据库环境与单实例数据库环境有很多共性,也有很多异性.对于数据库补丁的更新同样如此,都可以通过opatch来完成.但RAC环境的补丁更新有几种不同的更新方式,甚至于可以在零停机的情 ...