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 ...
随机推荐
- Python爬虫一些操作headers与cookies的便捷工具
本篇文章主要是爬虫中常用的便捷处理方法整理,转载请注明出处 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-08-14 13: ...
- Java for LeetCode 106 Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal Total Accepted: 31041 Total Submissions: ...
- uboot中添加自定义命令
uboot中可以通过修改源程序来添加自定义命令,进一步扩展uboot的功能. 我想在uboot下添加一条新的命令(名为varcpy),用来拷贝uboot中的环境变量. 修改方式如下: 创建新文件com ...
- Codeforces Round #553 (Div. 2) 题解
昨晚深夜修仙上紫记,虽然不错还是很有遗憾的. A. Maxim and Biology 看完就会做的题,然而手速跟不上 #include<cstdio> #include<iostr ...
- shell将字符串转换为大写变量并将小写作为变量值
group_name='a b c d e f g' for a in $group_name; do typeset -u a ; echo "$a='$(echo $a | tr '[A ...
- (5)表单Action后台验证
/day31/src/cn/itcast/web/struts2/user/UserAction.java package cn.itcast.web.struts2.user; import com ...
- PYTHON 爬虫笔记九:利用Ajax+正则表达式+BeautifulSoup爬取今日头条街拍图集(实战项目二)
利用Ajax+正则表达式+BeautifulSoup爬取今日头条街拍图集 目标站点分析 今日头条这类的网站制作,从数据形式,CSS样式都是通过数据接口的样式来决定的,所以它的抓取方法和其他网页的抓取方 ...
- 时尚创意VI矢量设计模板
时尚创意VI矢量设计模板 创意VI VI设计 企业VI 时尚背景 信封设计 封面设计 杯子 桌旗 帽子 EPS矢量素材下载 http://www.huiyi8.com/vi/
- RQNOJ 140 分配时间:dp
题目链接:https://www.rqnoj.cn/problem/140 题意: 小王参加的考试是几门科目的试卷放在一起考,一共给t分钟来做. 他现在已经知道第i门科目花k分钟可以拿到w[i][k] ...
- html5--2.7新的布局元素(4)-time
html5--2.7新的布局元素(4)-time 学习要点 了解微格式的概念 掌握time元素的用法 微格式的概念 HTML5中的微格式,是一种利用HTML5中的新标签对网页添加附加信息的方法,附加信 ...