M - Zjnu Stadium

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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) 

一个类似的题:
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(带权并查集,难想到)的更多相关文章

  1. hdu 3047–Zjnu Stadium(带权并查集)

    题目大意: 有n个人坐在zjnu体育馆里面,然后给出m个他们之间的距离, A B X, 代表B的座位比A多X. 然后求出这m个关系之间有多少个错误,所谓错误就是当前这个关系与之前的有冲突. 分析: 首 ...

  2. HDU 3047 Zjnu Stadium(带权并查集)

    题意:有一个环形体育场,有n个人坐,给出m个位置关系,A B x表示B所在的列在A的顺时针方向的第x个,在哪一行无所谓,因为假设行有无穷个. 给出的座位安排中可能有与前面矛盾的,求有矛盾冲突的个数. ...

  3. Hdu 2047 Zjnu Stadium(带权并查集)

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

  4. hdu 3047 Zjnu Stadium(加权并查集)2009 Multi-University Training Contest 14

    题意: 有一个运动场,运动场的坐席是环形的,有1~300共300列座位,每列按有无限个座位计算T_T. 输入: 有多组输入样例,每组样例首行包含两个正整数n, m.分别表示共有n个人,m次操作. 接下 ...

  5. HDU3047 Zjnu Stadium 带权并查集

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

  6. hdu 5441 Travel 离线带权并查集

    Travel Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5441 De ...

  7. How Many Answers Are Wrong (HDU - 3038)(带权并查集)

    题目链接 并查集是用来对集合合并查询的一种数据结构,或者判断是不是一个集合,本题是给你一系列区间和,判断给出的区间中有几个是不合法的. 思考: 1.如何建立区间之间的联系 2.如何发现悖论 首先是如何 ...

  8. hdu 5441 travel 离线+带权并查集

    Time Limit: 1500/1000 MS (Java/Others)  Memory Limit: 131072/131072 K (Java/Others) Problem Descript ...

  9. hdu 2818 Building Block (带权并查集,很优美的题目)

    Problem Description John are playing with blocks. There are N blocks ( <= N <= ) numbered ...N ...

  10. hdu 3635 Dragon Balls (带权并查集)

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

随机推荐

  1. 解决:启动项目报错 java.lang.UnsatisfiedLinkError: D:\Java\apache-tomcat-8.0.17\bin\tcnative-1.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform

    启动项目报错如下: java.lang.UnsatisfiedLinkError: D:\Java\apache-tomcat-8.0.17\bin\tcnative-1.dll: Can't loa ...

  2. 微软2016校园招聘在线笔试-Professor Q's Software

    题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new softw ...

  3. Zookeeper + Guava loading cache 实现分布式缓存

    1. 概述 项目中,创建的活动内容存入redis,然后需要用到活动内容的地方,从redis去取,然后参与计算. 活动数据的一个特点是更新不频繁.数据量不大.因为项目部署一般是多机器.多实例,除了red ...

  4. 008Spring & JPA & Hibernate & MySQL

    01下载免安装版MySQL 02安装MySQL a)将MySQL压缩包解压到合适的位置,以C:\programmer\Tools\mysql-5.7.20-winx64路径为例: b)新建系统变量,变 ...

  5. 我所了解的关于JavaScript定义类和对象的几种方式

    原文:http://www.cnblogs.com/hongru/archive/2010/11/08/1871359.html 在说这个话题之前,我想先说几句题外话:最近偶然碰到有朋友问我“hois ...

  6. [转]乔布斯的薄伽梵歌 Steve’s Bhagavat Gita

    SRC: http://www.brucejia.net/ 2014年4月4日未分类apple.ios.steve jobs 编辑 Your time is limited, so don't was ...

  7. nginx参考资料

    什么是负载均衡? 官网的入门文章中文版 love2上关注数比较高的nginx教程 什么是反向代理,什么又是正向代理? csdn上浅谈Nginx之反向代理与负载均衡 Nginx 作为 WebSocket ...

  8. c# 设计模式 之:简单工厂、工厂方法、抽象工厂之小结、区别

    很多时候,我发现这三种设计模式难以区分,常常会张冠李戴闹了笑话.很有必要深入总结一下三种设计模式的特点.相同之处和不同之处. 1 本质 三个设计模式名字中都含有“工厂”二字,其含义是使用工厂(一个或一 ...

  9. JavaScript的本地对象、内置对象、宿主对象

    首先解释下宿主环境:一般宿主环境由外壳程序创建与维护,只要能提供js引擎执行的环境都可称之为外壳程序.如:web浏览器,一些桌面应用系统等.即由web浏览器或是这些桌面应用系统早就的环境即宿主环境. ...

  10. Python 爬虫 ajax爬取马云爸爸微博内容

    ajax爬取情况 有时候我们在用 Requests 抓取页面的时候,得到的结果可能和在浏览器中看到的是不一样的,在浏览器中可以看到正常显示的页面数据,但是使用 Requests 得到的结果并没有,这其 ...