Zjnu Stadium

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1686    Accepted Submission(s): 634

Problem Description
In 12th Zhejiang College Students Games 2007, there was 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.
 
Input
There are many test cases:
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
For every case: 
Output R, represents the number of incorrect request.
 
Sample Input
10 10
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
2

Hint

Hint:
(PS: the 5th and 10th requests are incorrect)

 

题意:懒得说了。。比赛的时候一直看错题意我擦。。

思路: 用并查集维护相对距离,若出现一个操作,两人的祖先相同,那么可以根据这个算出这两人的相对距离,若与操作所给的距离不一样,则为错误操作。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <utility>
#include <queue>
#include <stack>
using namespace std;
const int INF=<<;
const double eps=1e-;
const int N = ;
const int mod = ; int fa[N],d[N];
int n,m; void init()
{
for(int i=;i<=n;++i)
fa[i]=i, d[i]=;
} int find(int x)
{
//return fa[x]==x? x: fa[x]=find(fa[x]);
if(fa[x]==x)
return x;
int u=find(fa[x]);
d[x]+=d[fa[x]];
fa[x] = u;
return u;
} bool equ(int a,int b)
{
return (b-a)%mod == ;
} void run()
{
init();
int a,b,x;
int ta,tb;
int ans=;
while(m--)
{
scanf("%d%d%d",&a,&b,&x);
ta = find(a);
tb = find(b);
if(ta!=tb)
{
fa[tb]=ta;
d[tb]=d[a]-d[b]+x;
}
else
{
if(d[b]-d[a]!=x)
++ans;
}
}
printf("%d\n",ans);
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
run();
return ;
}

hdu3047 Zjnu Stadium (并查集)的更多相关文章

  1. hdu 3047 Zjnu Stadium 并查集高级应用

    Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  2. HDU3047 Zjnu Stadium 【带权并查集】

    HDU3047 Zjnu Stadium Problem Description In 12th Zhejiang College Students Games 2007, there was a n ...

  3. hdu3047 Zjnu Stadium【带权并查集】

    <题目链接> <转载于 >>> > 题目大意: 有n个人坐在zjnu体育馆里面,然后给出m个他们之间的距离, A B X, 代表B的座位比A多X. 然后求出这 ...

  4. Zjnu Stadium(hdu3047带权并查集)

    题意:一个300列的无限行的循环场地,a b d代表a,b顺时针相距d的距离,现在给你一些距离,判断是否有冲突,如果有冲突计算冲突的次数 思路:带权并查集 a,b的距离等于b到根节点的距离 - a到根 ...

  5. HDU3047 Zjnu Stadium

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  6. 带权并查集--hdu3047 ZJnu stadium

    题意:给出一个n,m,n表示的是有n 个人,m表示的是 有m 对关系: 接下来输入的就是这m对关系,a,b,x:表示的是a,b相距x个距离:然后判断输入的是否与这个数的上面的数信息一致, 输出不一致的 ...

  7. HDU3047 Zjnu Stadium 带权并查集

    转:http://blog.csdn.net/shuangde800/article/details/7983965 #include <cstdio> #include <cstr ...

  8. HDU 3407.Zjnu Stadium 加权并查集

    Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. Zjnu Stadium(加权并查集)

    Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

随机推荐

  1. VS2013 自动添加头部注释 -C#开发

    在团队开发中,头部注释是必不可少的.但在开发每次新建一个类都要复制一个注释模块也很不爽,所以得想个办法让开发工具自动生成我们所需要的模板.....操作方法如下: 方法/步骤 1 找你的vs安装目录, ...

  2. 九度OJ 1174:查找第K小数 (排序、查找)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6376 解决:2539 题目描述: 查找一个数组的第K小的数,注意同样大小算一样大.  如  2 1 3 4 5 2 第三小数为3. 输入: ...

  3. ios导航栏问题

    http://m.blog.csdn.net/article/details?id=47395605

  4. Git with SVN

    1)GIT是分布式的,SVN不是: 这 是GIT和其它非分布式的版本控制系统,例如SVN,CVS等,最核心的区别.好处是跟其他同事不会有太多的冲突,自己写的代码放在自己电脑上,一段时间后再提交.合并, ...

  5. Cannot run program “git.exe”: createprocess error=2,系统找不到指定的文件

    Android Studio提供VCS(Version Control System)版本控制系统,默认情况使用Git.GitHub工具需要配置git.exe路径,否则提示“cannot run pr ...

  6. 基于ajax的登录

    验证码 当登录一个网站的时候往往会有验证码. python生成随机验证码,需要使用到 PIL 模块 安装 : pip3 install pillow 1. 创建图片        我们现在写的验证码属 ...

  7. ListView多选和单选模式重新整理

    超简单的单选和多选ListView 在开发过程中,我们经常会使用ListView去呈现列表数据,比如商品列表,通话记录,联系人列表等等,在一些情况下,我们还需要去选择其中的一些列表数据进行编辑.以前, ...

  8. 【LeetCode-easy】Merge Two Sorted Lists

    思路:指针p用于串联怎个链表,比较两个指针的大小,连接较小的一个.如果一个链表到达链尾,连接另外一个链表余下来的所以节点. public ListNode mergeTwoLists(ListNode ...

  9. java 解析excle

    jjava解析excle或者csv文件并导出到web界面: 创建ExcelShower.java package com.ssm.controller; import java.io.File; im ...

  10. CodeForces - 540B School Marks —— 贪心

    题目链接:https://vjudge.net/contest/226823#problem/B Little Vova studies programming in an elite school. ...