HDU 3047 Zjnu Stadium(带权并查集,难想到)
Description
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.
Input
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
Output R, represents the number of incorrect request.
Sample Input
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
Sample Output
Hint
Hint: (PS: the 5th and 10th requests are incorrect) 一个类似的题:
https://www.cnblogs.com/yinbiao/p/9460772.html code:
#include<queue>
#include<set>
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<string>
#include<string.h>
#include<memory>
using namespace std;
#define max_v 50005
#define INF 9999999
int pa[max_v];
int sum[max_v];
int n,m;
int ans;
void init()
{
for(int i=;i<=n;i++)
{
pa[i]=i;
sum[i]=;
}
}
int find_set(int x)
{
if(pa[x]!=x)
{
int t=pa[x];
pa[x]=find_set(pa[x]);
sum[x]+=sum[t];//!!!
}
return pa[x];
}
void union_set(int a,int b,int v)
{
int x=find_set(a);
int y=find_set(b);
if(x==y)
{
if(sum[a]-sum[b]!=v)//!!!
ans++;
}else
{
pa[x]=y;
sum[x]=sum[b]-sum[a]+v;//!!!
}
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
int x,y,w;
ans=;
init();
for(int i=;i<m;i++)
{
scanf("%d %d %d",&x,&y,&w);
union_set(x,y,w);
}
printf("%d\n",ans);
}
return ;
}
HDU 3047 Zjnu Stadium(带权并查集,难想到)的更多相关文章
- hdu 3047–Zjnu Stadium(带权并查集)
题目大意: 有n个人坐在zjnu体育馆里面,然后给出m个他们之间的距离, A B X, 代表B的座位比A多X. 然后求出这m个关系之间有多少个错误,所谓错误就是当前这个关系与之前的有冲突. 分析: 首 ...
- HDU 3047 Zjnu Stadium(带权并查集)
题意:有一个环形体育场,有n个人坐,给出m个位置关系,A B x表示B所在的列在A的顺时针方向的第x个,在哪一行无所谓,因为假设行有无穷个. 给出的座位安排中可能有与前面矛盾的,求有矛盾冲突的个数. ...
- Hdu 2047 Zjnu Stadium(带权并查集)
Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 3047 Zjnu Stadium(加权并查集)2009 Multi-University Training Contest 14
题意: 有一个运动场,运动场的坐席是环形的,有1~300共300列座位,每列按有无限个座位计算T_T. 输入: 有多组输入样例,每组样例首行包含两个正整数n, m.分别表示共有n个人,m次操作. 接下 ...
- HDU3047 Zjnu Stadium 带权并查集
转:http://blog.csdn.net/shuangde800/article/details/7983965 #include <cstdio> #include <cstr ...
- hdu 5441 Travel 离线带权并查集
Travel Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5441 De ...
- How Many Answers Are Wrong (HDU - 3038)(带权并查集)
题目链接 并查集是用来对集合合并查询的一种数据结构,或者判断是不是一个集合,本题是给你一系列区间和,判断给出的区间中有几个是不合法的. 思考: 1.如何建立区间之间的联系 2.如何发现悖论 首先是如何 ...
- hdu 5441 travel 离线+带权并查集
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Descript ...
- hdu 2818 Building Block (带权并查集,很优美的题目)
Problem Description John are playing with blocks. There are N blocks ( <= N <= ) numbered ...N ...
- hdu 3635 Dragon Balls (带权并查集)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
随机推荐
- linux ssh免密登陆
大致流程: 两台linux系统A B 如果A要登陆到B 1.生成A的密钥对 2.将A的公钥拷贝到B的authorized_keys中即可 可以使用命令:ssh-copy-id -i ~/.ssh/id ...
- oracle数据库的安装与连接关键点
一.window xp系统上安装Oracle Database 10G 解锁Scott.Hr账号并重置口令 远程连接数oracle数据库地址 二.在Mac系统上使用Navicat远程连接oracle数 ...
- Thymeleaf学习记录(2)--自动编译设置
了方便每次修改HTML文件都能实时刷新,做一下更改. 在application.properties文件加入以下命令: #thymeleaf start spring.thymeleaf.mode=H ...
- iView开始结束时间组件
演示地址:https://run.iviewui.com/TGIKGkIt 测试页面文件: <template> <div> <startEndTime @newEndT ...
- 改bug后 fix bug 时,一个不错的修复描述模板
*问题原因:* 问题出现的原因.*解决方法:* 问题的解决方案.*影响分支:* 影响哪些分支. *相关修改:* 具体的修改文件列表.*自测结果:* 自行测试了哪些用例,将大概步骤描述出来. *影响功能 ...
- Sql server 查询数据库中包含某字段的所有的表
我们有时候会需要查询数据库中包含某字段的所有的表,去进行update,这时就可以用下面的SQL来实现: select object_name(id) objName,Name as colName f ...
- 一次spring aop 切面的问题
最新项目有个新需求,要在已经写好的controller里面 加上传入参数的验证,由于有多个 controller而且验证每个都要调用其他的服务,故决定采用spring的aop方式. 1.添加aop的验 ...
- mac下 IDEA 的pom下 出现 Cannot access in offline mode 问题
在mac下 配置完maven后发现总是不能引入最新的jar包,google了好久总算找到解决办法: 默认带有work offline ,不清楚这个是干嘛用的.勾选掉 了就行了.
- Attribute+Reflection,提高代码重用
这篇文章两个目的,一是开阔设计的思路,二是实例代码可以拿来就用. 设计的思路来源于<Effective c#>第一版Item 24: 优先使用声明式编程而不是命令式编程.特别的地方是,希望 ...
- 让UpdatePanel支持文件上传(1):开始 .
UpdatePanel从一开始就无法支持AJAX的文件上传方式.Eilon Lipton写了一篇文章解释了这个问题的原因.文章中提供了两个绕开此问题的方法: 将“上传”按钮设为一个传统的PostBac ...