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, ...
随机推荐
- Embedded之Stack之二
1 Function Programming languages make functions easy to maintain and write by giving each function i ...
- Vs2010删除空白行
在copy了别人的代码之后,出现了大量的空白行,批量删除空白行方法为: 查找内容:^:b*$\n 替换为: 查找范围:当前文档 使用:正则表达式
- 教材配套PPT初稿
1-10章初稿,基本完整.有些粗糙,后面可能会稍作调整. 附更新情况如下: 1.增加了第10章内容: 2.第5章增加了一些内容: 3.第3章内容部分更新: 4.增加了第8-9章内容. 订正:更新了第8 ...
- Visual Studio 推荐插件以及一些设置
Microsoft Visual Studio 作为微软自家的 IDE 集成 NuGet 包管理器,是的引用一些不同版本组件DLL十分方便. 集成编译环境,强大的 Debug 断点.附加功能 项目模板 ...
- css单双行样式
#random_box li:nth-child(odd) {//双行 background: #fff5c4; } #random_box li:nth-child(even) {//单行 back ...
- 崂山白花蛇草水 权值线段树套KDtree
Description 神犇Aleph在SDOI Round2前立了一个flag:如果进了省队,就现场直播喝崂山白花蛇草水.凭借着神犇Aleph的实 力,他轻松地进了山东省省队,现在便是他履行诺言的时 ...
- Linux:只复制文件权限和所有者
在Linux上,怎么把一个文件的<权限和所有者>赋给另一个文件呢? chown命令可以设置所有者和用户组:chmod可以设置文件的权限.这两个命令都支持使用另一个文件做为引用(RFILE) ...
- CSS学习笔记之选择器
目录 1.元素选择器 2.继承 3.选择器分组 4.声明分组 5.后代选择器 6.子元素选择器 7.相邻兄弟选择器 8.类选择器 9.ID 选择器 10.属性选择器 11.伪类 12.伪元素 1.元素 ...
- Python检测删除你的好友-wxpy模块(发送特殊字符式)
下面是代码: from wxpy import *import timeprint("本软件采用特殊字符检测,即对方收不到任何信息!")print("或许某个版本微信就会 ...
- 渗透实战(周一):VMmare Fusion安装Kali Linux和win7虚拟机
高配笔记本电脑i5/8G/265G .VMware Fusion .Kali Linux镜像 .Win7镜像 第一:下载软件 1.如果你是苹果系统,建议下载最新VMware Fusion 11.0. ...