Dragon Ball--hdoj
Dragon Ball
His country has N cities and there are exactly N dragon balls in the world. At first, for the ith dragon ball, the sacred dragon will puts it in the ith city. Through long years, some cities' dragon ball(s) would be transported to other cities. To save physical
strength WuKong plans to take Flying Nimbus Cloud, a magical flying cloud to gather dragon balls.
Every time WuKong will collect the information of one dragon ball, he will ask you the information of that ball. You must tell him which city the ball is located and how many dragon balls are there in that city, you also need to tell him how many times the
ball has been transported so far.
as the follow format: T A B : All the dragon balls which are in the same city with A have been transported to the city the Bth ball in. You can assume that the two cities are different. Q A : WuKong want to know X (the id of the city Ath ball is in), Y (the
count of balls in Xth city) and Z (the tranporting times of the Ath ball). (1 <= A, B <= N)
2
3 3
T 1 2
T 3 2
Q 2
3 4
T 1 2
Q 1
T 1 3
Q 1
Case 1:
2 3 0
Case 2:
2 2 1
3 3 2#include<stdio.h>
#include<string.h>
int pre[1010],num[1010],time[1010],Case=1;
int find(int x)
{
if(x==pre[x])
return x;
int p=pre[x];
time[x]+=time[p];
return pre[x];
}
void join(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
{
pre[fx]=fy;
num[fy]+=num[fx];
time[fx]++;
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i,u,v,m,n;
char ch;
scanf("%d%d",&m,&n);
for(i=0;i<=m;i++)
{
pre[i]=i;
time[i]=0;num[i]=1;
}
while(n--)
{
getchar();
scanf("%c%d",&ch,&u);
if(ch=='T')
{
scanf("%d",&v);
join(u,v);
}
else
{
v=find(u);
printf("Case %d:\n",Case++);
printf("%d %d %d\n",v,num[v],time[u]);
}
}
}
return 0;
}
Dragon Ball--hdoj的更多相关文章
- HDU 4362 Dragon Ball 贪心DP
Dragon Ball Problem Description Sean has got a Treasure map which shows when and where the dragon ...
- Kattis dragonball1 Dragon Ball I(最短路)
There is a legendary tale about Dragon Balls on Planet X: if one collects seven Dragon Balls, the Dr ...
- 龙珠 超宇宙 [Dragon Ball Xenoverse]
保持了动画气氛实现的新时代的龙珠视觉 今年迎来了[龙珠]系列的30周年,为了把他的魅力最大限度的发挥出来的本作的概念,用最新的技术作出了[2015年版的崭新的龙珠视觉] 在沿袭了一直以来优秀的动画世界 ...
- HDU-3872 Dragon Ball 线段树+DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3872 题意:有n个龙珠按顺序放在一列,每个龙珠有一个type和一个权值,要求你把这n个龙珠分成k个段, ...
- HDU 4362 Dragon Ball 线段树
#include <cstdio> #include <cstring> #include <cmath> #include <queue> #incl ...
- hdoj 3635 Dragon Balls【并查集求节点转移次数+节点数+某点根节点】
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3635 Dragon Balls(并查集)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3635 Dragon Balls (带权并查集)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3635 Dragon Balls
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 3635 Dragon Balls(并查集应用)
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...
随机推荐
- Mysql Event 自动分表
create table TempComments Like dycomments; 上述 SQL语句创建的新表带有原表的所有属性,主键,索引等. 自动分表怎么做呢? 使用上述语句自动创建分表. 那么 ...
- JavaScript中比较运算符的使用
比较运算符的基本操作过程是:首先对操作数进行比较,这个操作数可以是数字也可以是字符串,然后返回一个布尔值true或false. 在JavaScript中常用的比较运算符如下表所示. 例如,某商场店庆搞 ...
- Eclipse的菜单简介
在Eclipse工作台的上方提供了菜单栏,该菜单栏包含了实现Eclipse各项功能的命令,并且与编辑器相关,即菜单栏中的菜单项与当前编辑器内打开的文件是关联的.例如,编辑器内没有打开任何文件,那么,将 ...
- USB 接口探测分类
USB 接口探测分类 SDP (Standand Downstream Port) 标准下行接口 标准USB都支持的接口 这种端口的D+和D-线上具有15kΩ下拉电阻.限流值如上讨论:挂起时为2.5m ...
- 【备份工具】mydumper
Mydumper主要特性:是一个针对MySQL的高性能多线程备份和恢复工具,开发人员主要来自MySQL,Facebook,SkySQL公司. 特性: 1:轻量级C语言写的 2:执行速度比mysqldu ...
- 《Linux程序设计》笔记(一)入门
1. 头文件 使用-I标志来包含头文件. gcc -I/usr/openwin/include fred.c 2. 库文件 通过给出 完整的库文件路径名 或 用-l标志 来告诉编译器要搜索的库文件. ...
- Linux命令小记
以下说法都是基于普通用户的角度,如果是root,可能会有不同. (1)rm -r或-R选项:递归删除目录及其内容(子目录.文件) rm默认无法删除目录,如果删除空目录,可以使用-d选项.如果目录非空, ...
- (1)dotnet开源电商系统-brnshop&brnMall 和老外开发的nopCommerce(dotnet两套电商来PK--第一篇)
一直想做电商软件,但是实在不想学PHP了,所以前后关注了这两个开源电商系统.一个是国人出品的,一个据说是俄罗斯人写得(不知道对不对).目前两个开源软件都在学习了解中,以下的博文可能会涉及到这两套系统, ...
- NET MVC FileResult 导出/下载 文件/Excel
参考http://www.cnblogs.com/ldp615/archive/2010/09/17/asp-net-mvc-file-result.html 1.引入NPOI 2.代码 using ...
- LINUX命令行如何查看memcache运行状态
(附加)如何查看memcache服务器端版本: ./memcached -h memcache的运行状态可以方便的用 stats 命令显示. 首先用telnet 127.0.0.1 11211这样 ...