hdu 3635】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=3635 1-n个城市,对应放着编号1-n的龙珠. 两种操作 T A B 把编号A的龙珠所在城市内的全部龙珠放到有编号B的龙珠的城市内 Q A 查询编号A的龙珠的信息,输出三个数,A所在城市,A所在城市龙珠数目,A转移到该城市所用次数 思路:对球进行并查集维护,sum[a]表示a点移动到目前根的次数,每次合并的时候把A球根节点的sum设为1,这是并查集一个经典的操作,转移次数问题解决.A球所属城市的龙珠数目单开一…
http://acm.hdu.edu.cn/showproblem.php?pid=3635 题意: 有n颗龙珠和n座城市,一开始第i颗龙珠就位于第i座城市,现在有2种操作,第一种操作是将x龙珠所在城市的所有龙珠移至y龙珠所在城市,第二种操作是计算x龙珠所在城市y,y城市龙珠个数,以及x龙珠移动的次数. 思路:num[x]用来维护x城市所包含的龙珠个数,cnt[x]维护x龙珠所移动的次数. #include<iostream> #include<algorithm> #includ…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3363    Accepted Submission(s): 1304 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, so it's too difficult for Monkey King(WuKong) to gather all of the dragon balls together. His country has N cities and there are exactly N dragon bal…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7926    Accepted Submission(s): 2937 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
Problem - 3635 切切水题,并查集. 记录当前根树的结点个数,记录每个结点相对根结点的转移次数.1y~ 代码如下: #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; ; struct MFS { int fa[N], tm[N], cnt[N]; ; i < N; i++) fa[i] = i,…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2909    Accepted Submission(s): 1125 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
这道题说,在很久很久以前,有一个故事.故事的名字叫龙珠.后来,龙珠不知道出了什么问题,从7个变成了n个. 在悟空所在的国家里有n个城市,每个城市有1个龙珠,第i个城市有第i个龙珠. 然后,每经过一段时间,城市i的所有的龙珠都会被转移到城市j中. 现在有两种操作: 1. T A B,表示将A龙珠所在城市的所有龙珠全部转移到B龙珠所在城市去. 2. Q A,表示询问A龙珠所在的城市X,以及X城市有几个龙珠,A龙珠被转移了几次. 输入: 第一行输入1个整型数字t,表示一共t组测试样例. 接下来,每组样…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5340    Accepted Submission(s): 2014 Problem Description Five hundred years later, the number of dragon balls will increase unexpect…
题意: 给定n个点 oper个操作 每个点有1个龙珠 下面2种操作: T u v 把u点所有龙珠搬到v Q u  问u点当前所在城市 u点所在城市有几个龙珠 u点被移动几次 思路: 并查集可以求出 u 点所在城市,记录每个点的 son(子节点数)可以求出 某城市的龙珠数量 用step 记录每个点被移动了几次 #include<stdio.h> #include<string.h> inline int Max(int a,int b){return a>b?a:b;} #de…