PKU1988磁铁
| Time Limit: 2000MS | Memory Limit: 30000K | |
| Total Submissions: 16258 | Accepted: 5579 | |
| Case Time Limit: 1000MS | ||
Description
Write a program that can verify the results of the game.
Input
* Lines 2..P+1: Each of these lines describes a legal operation. Line 2 describes the first operation, etc. Each line begins with a 'M' for a move operation or a 'C' for a count operation. For move operations, the line also contains two integers: X and Y.For count operations, the line also contains a single integer: X.
Note that the value for N does not appear in the input file. No move operation will request a move a stack onto itself.
Output
Sample Input
6
M 1 6
C 1
M 2 4
M 2 6
C 3
C 4
Sample Output
1
0
2
Source
#include <iostream>
#include<stdio.h>
using namespace std;
#define maxn 30003
int num[maxn];
int dis[maxn]={0};
int father[maxn];
int find_set(int x)
{
if(x!=father[x])
{
int temp=father[x];
father[x]=find_set(father[x]);
dis[x]+=dis[temp];
}
return father[x];
}
void union_set(int a,int b)
{
int fathera=find_set(a);
int fatherb=find_set(b);
father[fatherb]=fathera;
dis[fatherb]=num[fathera];
num[fathera]+=num[fatherb];
}
int main()
{
int n;
char ch[2];
int a,b;
scanf("%d",&n);
int i;
for(i=0;i<maxn;i++)
{
father[i]=i;
num[i]=1;
}
while(n--)
{
scanf("%s%d",&ch,&a);
if(ch[0]=='M')
{
scanf("%d",&b);
union_set(a,b);
}
else
{
int temp=find_set(a);
printf("%d\n",num[temp]-dis[a]-1);
}
}
return 0;
}
PKU1988磁铁的更多相关文章
- 利用智能手机(Android)追踪一块磁铁(三)
更新磁铁追踪算法的源代码,Android Studio项目工程 github地址:https://github.com/amazingyyc/MagnetLocate 说明:将磁铁的位置信息封装成消息 ...
- 利用智能手机(Android)追踪一块磁铁(二)
在上一篇博客中提到了利用磁场强度推算传感器位置坐标的公式,下面就介绍怎么利用智能手机完成磁铁的追踪(任何具有磁感应器的装置均可以),这里主要是利用Android手机. 1:程序步骤: 首先将磁铁放置在 ...
- 利用智能手机(Android)追踪一块磁铁(一)
之前看到一个外国人用iPhone做了一个追踪磁铁的Demo感觉不错(参考视频:http://v.youku.com/v_show/id_XODM2MjczNzE2.html),然后我就参考做了一个An ...
- 利用智能手机(Android)追踪一块磁铁(转)
利用智能手机(Android)追踪一块磁铁(一) 利用智能手机(Android)追踪一块磁铁(二) 利用智能手机(Android)追踪一块磁铁(三)
- windows phone 8.1开发:磁铁|Tile更新
原文出自:http://www.bcmeng.com/tile/ 上一篇给大家分享了toast通知操作的方法,这一篇文章我们就来看windows phone 8.1开发中的磁铁更新.磁铁是window ...
- MJJ玩磁铁
题目: Problem D: MJJ玩磁铁 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 139 Solved: 9[Submit][Status][ ...
- Win10手动添加开始磁铁
1.移动到C:\Users\spring\AppData\Roaming\Microsoft\Windows\Start Menu\Programs 2.拖拽
- WPF 控件总结
内容控件:1.Button:当Button.IsCancel="True"时,点击按钮,对话框关闭.当Button.IsDefault="True",按回车触发 ...
- Windows phone应用开发[17]-xap提交异常处理
在windows phone 应用提交操作上早在2011年时就写过一篇Windows phone 应用开发[4]-应用发布,那时wp应用提交官方市场的流程繁杂[超过了5步].因为上传和填写应用信息页面 ...
随机推荐
- css 发光样式
结果: css/style1.css: /*setup*/ *{ margin:; padding:; } @font-face { font-family: 'Monoton'; font-styl ...
- Thread之七:Object里的wait、notify、notifyAll的使用方法
wait().notify().notifyAll()是三个定义在Object类里的方法,可以用来控制线程的状态 public final native void notify(); public f ...
- Centos6.x搭建lnmp环境
查看系统版本 #cat /etc/redhat-release CentOS release 6.7 (Final) 配置静态ip #vi /etc/sysconfig/network-scripts ...
- java 输入输出流 关于InputStream 和 OutputSteam 实现文本一行一行读入和 文本一行一行输出
对 byte 有了新的认知:byte表示一个字节 因此他可以表示成 一个 数字: 一个数字可以映射成一个字符:InputStream 中的 read() 函数 的意思是读入一个整数,读入一个整数的 ...
- PXE_kickstart安装Ubuntu
1.准备 1.1.apt-get remove iptables卸载IP过滤表1.2.下载镜像 2.DHCP安装2.1.apt-get install dhcp3-server(在ubuntu12中, ...
- 异步任务中的重新进入(Reentrancy)
一个按钮,点击执行一个任务.我们可能直接在它的 Click 事件中写下了执行任务的代码. 一般我们无需担心这样的代码会出现什么问题——但是,这样的好事情只对同步任务有效:一旦进入了异步世界,这便是无尽 ...
- oracle-分区(笔记)
partition by 用于指定分区方式 range 表示分区的方式是范围划分 partition pn 用于指定分区的名字 values less than 指定分区的上界(上限) ------- ...
- Mac 中的sublime text3 如何安装插件
Mac中sublime text安装插件的步骤: 在sublime text中顶部标签栏中View–>Show Console,或者按快捷键control+`打开. 在下面输入框中粘贴进以下代码 ...
- Nginx配置(需要把nginx的根目录指向ftp上传文件的目录。)
改成
- sentry docker-compsoe 安装以及简单使用
1. 准备环境 docker docker-compose 2. 安装 a. docker-compose git clone git clone https://github.com/get ...