How Many Answers Are Wrong
来源:互联网 发布:海森梅尔什么档次 知乎 编辑:程序博客网 时间:2024/05/16 06:24
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.
A single line with a integer denotes how many answers are wrong.
10 51 10 1007 10 281 3 324 6 416 6 1
1
带权的并查集,a--是不包括左端点,方便合并。其二,路径压缩,find,把所有的下层节点,合并到根节点。
#include<iostream>
using namespace std;
struct node {
int parent;
int len;
}p[200005];
void init(int n)
{
for(int i=0;i<=n;i++)
{
p[i].parent=i;
p[i].len=0;
}
}
int find(int a)
{
if(a==p[a].parent)
return a;
int r=find(p[a].parent);
p[a].len+=p[p[a].parent].len;
return p[a].parent=r;
}
bool combine(int a,int b,int k)
{
int p1=find(a);
int p2=find(b);
if(p1==p2)
{
return p[b].len-p[a].len!=k;
}
else{
p[p2].parent=p1;
p[p2].len=k+p[a].len-p[b].len;
return false;
}
}
int main()
{
//freopen("in.txt","r",stdin);
int n,m;
while(cin>>n>>m)
{
init(n);
int re=0;
while(m--)
{
int a,b,k;
cin>>a>>b>>k;
a--;
if(combine(a,b,k))
{
re++;
}
}
cout<<re<<endl;
}
return 0;
}
- How Many Answers Are Wrong
- How Many Answers Are Wrong
- How Many Answers Are Wrong
- How Many Answers Are Wrong
- How Many Answers Are Wrong
- HDU 3038 How Many Answers Are Wrong
- HDU 3038 How Many Answers Are Wrong
- hdoj 3038 How Many Answers Are Wrong
- hdu3038 How Many Answers Are Wrong
- hdu 3038 How Many Answers Are Wrong
- hdu 3038 How Many Answers Are Wrong
- HDU3038 How Many Answers Are Wrong
- HDU 3038 How Many Answers Are Wrong
- HDU-3038-How Many Answers Are Wrong
- HDU How Many Answers Are Wrong
- HDOJ 3038 How Many Answers Are Wrong
- hdu 3038 How Many Answers Are Wrong
- HDU 3038 How Many Answers Are Wrong
- 堆排序算法及其c语言泛型编程
- SecureCRT使用图形程序故障
- HDU 1997汉诺塔VII
- Android中Acition和Category常量表
- NSString常用
- How Many Answers Are Wrong
- Ajax json 问题
- 关于jari和qc的比较
- Hive基础
- SVN备份方案
- Webservice_09_Stax的基本操作(基于光标,基于迭代模型和过滤器)
- linux 进程间通信--systemV 信号量 实例
- Tomcat 生产服务器性能优化
- Mfc 中多个SliderCtrl滑动事件的捕捉