Zjnu Stadium(加权并查集)
Zjnu Stadium
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3186 Accepted Submission(s):
1226
a new stadium built in Zhejiang Normal University. It was a modern stadium which
could hold thousands of people. The audience Seats made a circle. The total
number of columns were 300 numbered 1--300, counted clockwise, we assume the
number of rows were infinite.
These days, Busoniya want to hold a large-scale
theatrical performance in this stadium. There will be N people go there numbered
1--N. Busoniya has Reserved several seats. To make it funny, he makes M requests
for these seats: A B X, which means people numbered B must seat clockwise X
distance from people numbered A. For example: A is in column 4th and X is 2,
then B must in column 6th (6=4+2).
Now your task is to judge weather the
request is correct or not. The rule of your judgement is easy: when a new
request has conflicts against the foregoing ones then we define it as incorrect,
otherwise it is correct. Please find out all the incorrect requests and count
them as R.
For every case:
The
first line has two integer N(1<=N<=50,000),
M(0<=M<=100,000),separated by a space.
Then M lines follow, each line
has 3 integer A(1<=A<=N), B(1<=B<=N), X(0<=X<300) (A!=B),
separated by a space.
Output R, represents the number of
incorrect request.
1 2 150
3 4 200
1 5 270
2 6 200
6 5 80
4 7 150
8 9 100
4 8 50
1 7 100
9 2 100
有n个人坐在zjnu体育馆里面,然后给出m个他们之间的距离, A B X, 代表B的座位比A多X. 然后求出这m个关系之间有多少个错误,所谓错误就是当前这个关系与之前的有冲突。
教训:
思路:

#include<iostream>
#include<cstdio>
using namespace std;
#define MAXN 50010
int n,m,father[MAXN],way[MAXN],ans;
void before()
{
for(int i=;i<MAXN;i++)father[i]=i,way[i]=;
ans=;
}
int find(int x)
{
if(x==father[x])return father[x];
int fa=father[x];
father[x]=find(father[x]);
way[x]+=way[fa];
return father[x];
}
void unit(int x,int y,int x1,int y1,int z)
{
father[y1]=x1;
way[y1]=way[x]+z-way[y];
}
int main()
{
while(scanf("%d%d",&n,&m)==)
{
before();
int x,y,z;
while(m--)
{
scanf("%d%d%d",&x,&y,&z);
int f1=find(x),f2=find(y);
if(f1!=f2)unit(x,y,f1,f2,z);
else if(way[y]-way[x]!=z)ans++;
}
printf("%d\n",ans);
}
}
Zjnu Stadium(加权并查集)的更多相关文章
- HDU 3407.Zjnu Stadium 加权并查集
Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu3047 Zjnu Stadium (并查集)
Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3047 Zjnu Stadium(并查集)
题意: 300个座位构成一个圈. 有N个人要入座. 共有M个说明 :A B X ,代表B坐在A顺时针方向第X个座位上.如果这个说明和之前的起冲突,则它是无效的. 问总共有多少个无效的. 思路: 并查集 ...
- hdu 3047 Zjnu Stadium(加权并查集)2009 Multi-University Training Contest 14
题意: 有一个运动场,运动场的坐席是环形的,有1~300共300列座位,每列按有无限个座位计算T_T. 输入: 有多组输入样例,每组样例首行包含两个正整数n, m.分别表示共有n个人,m次操作. 接下 ...
- hdu 3635 Dragon Balls(加权并查集)2010 ACM-ICPC Multi-University Training Contest(19)
这道题说,在很久很久以前,有一个故事.故事的名字叫龙珠.后来,龙珠不知道出了什么问题,从7个变成了n个. 在悟空所在的国家里有n个城市,每个城市有1个龙珠,第i个城市有第i个龙珠. 然后,每经过一段时 ...
- A Bug's Life(加权并查集)
Description Background Professor Hopper is researching the sexual behavior of a rare species of bug ...
- A Bug's Life(加权并查集)
Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs ...
- P1196 银河英雄传说(加权并查集)
P1196 银河英雄传说 题目描述 公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦 创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在 ...
- 洛谷 P2024 [NOI2001]食物链(种类并查集,加权并查集)
传送门 解题思路 加权并查集: 什么是加权并查集? 就是记录着每个节点到它的父亲的信息(权值等). 难点:在路径压缩和合并节点时把本节点到父亲的权值转化为到根节点的权值 怎么转化呢? 每道题都不一样Q ...
随机推荐
- DataGridView自定义RichTextBox列
https://www.codeproject.com/Articles/31823/RichTextBox-Cell-in-a-DataGridView-2 RichText是用图片显示的,当Sel ...
- iOS MVVM+RAC 从基础到demo
一.关于经典模式MVC的简介 MVC是构建iOS App的标准模式,是苹果推荐的一个用来组织代码的权威范式,市面上大部分App都是这样构建的,具体组建模式不细说,iOS入门者都比较了解(虽然不一定能完 ...
- A. Playing with Paper
这是Codeforces Round #296 (Div. 2)的A题,题意就是: 小明有一张长为a,宽为b的纸,每当要折纸鹤时,就从纸上剪下一个正方形,然后,剩下的纸还可以剪出正方形,要是剩下的纸刚 ...
- 在ubuntu怎样修改默认的编码格式
ubuntu修改系统默认编码的方法是: 1. 参考 /usr/share/i18n/SUPPORTED 编辑/var/lib/locales/supported.d/* gedit /var/lib/ ...
- Android字符设备驱动开发基于高通msm8916【原创 】
本人才疏浅学,写一篇文档总结自己在msm8916平台上移植自己编写的简单的字符设备驱动开发的整个流程.这个小项目的主要功能是开发一个简单的APP,APP通过JNI去调用位于kernel的字符设备驱动. ...
- ActiveMQ 了解
Active MQ 是JMS的一个具体实现,所以首先要对JMS有所了解. 1. JMS: 定义:Java消息服务(Java Message Service),是Sun是提出来的为J2EE提 ...
- 算法(Algorithms)第4版 练习 1.3.12
方法实现: package com.qiusongde; import java.util.Iterator; import java.util.NoSuchElementException; imp ...
- PYTHON 爬虫笔记七:Selenium库基础用法
知识点一:Selenium库详解及其基本使用 什么是Selenium selenium 是一套完整的web应用程序测试系统,包含了测试的录制(selenium IDE),编写及运行(Selenium ...
- KafkaSpout 重复消费问题解决
使用https://github.com/nathanmarz/storm-contrib来对接Kafka0.7.2时, 发现kafkaSpout总会进行数据重读, 配置都无问题, 也没报错 进行de ...
- logback备注
<?xmlversion="1.0"encoding="UTF-8"?> <!-- <configuration>包含的属性 sc ...