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. python 基础 2.7 range与xrange的区别

    #/usr/bin/python #coding=utf-8 #@Time :2017/10/25 19:22 #@Auther :liuzhenchuan #@File :range与xrange的 ...

  2. 九度OJ 1032:ZOJ (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4569 解决:2561 题目描述: 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的 ...

  3. 题解 P3805 【【模板】manacher算法】

    题解 P3805 [[模板]manacher算法] 我们先看两个字符串: ABCCBA ABCDCBA 显然这两字符串是回文的 然而两个串的对称中心的特性不同,第一个串,它的对称中心在两个C中间,然而 ...

  4. JavaScript 四种显示数据方式

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 升级pip3的正确姿势

    如果你的电脑里装了两个python,就会有两个pip,一个是pip2,一个是pip3,还有可能出现一个既没有2也没有3的pip,一般情况下,pip等于pip2 有时候我们使用pip安装东西会提示我们p ...

  6. 设置ubuntu默认输入python进入python3

    执行下面两条命令 sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100 sudo update- ...

  7. 【转】如何让虚拟目录里面的webconfig不继承网站的设置

    [转]http://www.cnblogs.com/Sue_/articles/2037556.html 必須在上一层虚拟目录(如根目录)所在的Web.config加上 如:<location ...

  8. BeginPaint和GetDC有什么区别

    windows编程问题 第一种情况显示出来的字很正常. case WM_PAINT: gdc = BeginPaint (hwnd, &ps); TextOut (gdc, 0, 0, s, ...

  9. react-native 支持 gif 图片

    只需要在android/app/build.gradle中的dependencies字段中添加: compile 'com.facebook.fresco:animated-gif:0.13.0' 然 ...

  10. 关于connect: network is unreachable 问题的解决【转】

    本文转载自:https://blog.csdn.net/liukun321/article/details/6662950 由于发现原创文章,在未署名作者及出处的情况下被转载.在以后所有的原创文章开头 ...