poj1988_Cube Stacking
Time Limit: 2000MS | Memory Limit: 30000K | |
Total Submissions: 24130 | Accepted: 8468 | |
Case Time Limit: 1000MS |
Description
moves and counts.
* In a move operation, Farmer John asks Bessie to move the stack containing cube X on top of the stack containing cube Y.
* In a count operation, Farmer John asks Bessie to count the number of cubes on the stack with cube X that are under the cube X and report that value.
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 <cstdio>
#include <cstring> using namespace std; int up[];//该数上面的数
int n[];//该集合总数
int a[];//保存他的父节点 int father(int t){
if(t==a[t]){
return t;
}
int fa=a[t];
a[t]=father(a[t]);
up[t]+=up[fa]; return a[t];
} int main()
{
int p;
//char c;
int t1,t2;
int t3;
while(scanf("%d",&p)!=EOF){
for(int i=;i<=p;i++){
a[i]=i;
up[i]=;
n[i]=;
}
char s[];
for(int i=;i<p;i++){
scanf("%s",s);
if(s[]=='M'){
scanf("%d%d",&t1,&t2);
int fa=father(t1);
int fb=father(t2);
if(fa!=fb){
a[fb]=fa;
up[fb]+=n[fa];
n[fa]+=n[fb];
}
}else{
scanf("%d",&t3);
int ans=father(t3);
printf("%d\n",n[ans]-up[t3]-);
}
}
}
return ;
}
poj1988_Cube Stacking的更多相关文章
- CSS——关于z-index及层叠上下文(stacking context)
以下内容根据CSS规范翻译. z-index 'z-index'Value: auto | <integer> | inheritInitial: autoApplies to: posi ...
- poj.1988.Cube Stacking(并查集)
Cube Stacking Time Limit:2000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u Submi ...
- 关于stacking context和CSS z-index的总结
HTML中决定元素叠加顺序的CSS属性最有名的应该是z-index了.但是,往往在项目中发现有些情况和我们的预期不太一致.经过研究和学习,总算搞清楚了其中的关系.简单总结如下: 只有Positione ...
- UVa 103 - Stacking Boxes(dp求解)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- 层叠上下文(The stacking context)
MDNThe stacking context 层叠上下文是HTML元素的三维概念,这些HTML元素在一条假想的相对于面向(电脑屏幕的)视窗或者网页的用户的z轴上延伸,HTML元素依据其自身属性按照优 ...
- POJ 1988 Cube Stacking(带权并查集)
Cube Stacking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 23678 Accepted: 8299 Ca ...
- Cube Stacking
Cube Stacking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 21350 Accepted: 7470 Case T ...
- UVa 103 Stacking Boxes --- DAG上的动态规划
UVa 103 题目大意:给定n个箱子,每个箱子有m个维度, 一个箱子可以嵌套在另一个箱子中当且仅当该箱子的所有的维度大小全部小于另一个箱子的相应维度, (注意箱子可以旋转,即箱子维度可以互换),求最 ...
- 层叠水平(stacking level)
运用上图的逻辑,上面的题目就迎刃而解,inline-blcok 的 stacking level 比之 float 要高,所以无论 DOM 的先后顺序都堆叠在上面. 不过上面图示的说法有一些不准确,按 ...
随机推荐
- 再谈Newtonsoft.Json高级用法
上一篇Newtonsoft.Json高级用法发布以后收到挺多回复的,本篇将分享几点挺有用的知识点和最近项目中用到的一个新点进行说明,做为对上篇文章的补充. 阅读目录 动态改变属性序列化名称 枚举值序列 ...
- android开发环境搭建(ubuntu15.04+jdk8+eclipse+android sdk)
开始学习android开发,首先对其环境对搭建比较重要.平台可以选择window/linux/mac等,这里,我选择ubuntu系统,方法比较原始,当然也可以直接用google提供的android s ...
- Good Bye 2016 //智商再次下线,边界爆炸.....
A B很水就略了.. C.又是一次wannafly一样的判断区间的..... 边界设为2000000 正好GG...... fst的时候立马想到上次也是这么wa过的...... 所以下次遇到这种题 ...
- 【jQuery】 jQuery上下飘动效果
jQuery实现图片上下飘动效果 function moveRocket() { $(".smallShip") //2000毫秒内top = top + 60: .animate ...
- Python笔记(3)迭代器与生成器
参考自:http://www.cnblogs.com/huxi/category/251137.html 迭代器 迭代器是访问集合内元素的一种方式,他不能倒退只能一直迭代下去.可以写到for循环in后 ...
- pod setup 安装的最新办法(大坑啊)
由于升级到10.11以后安装cocodpods难免会碰到各种问题,下面有列举出不同的解决办法,建议一个方法如果不行,把文件请了再用第二种方法, 流程是这样的:正常安装-->碰到问题-->查 ...
- 移动端浏览器和微信浏览器上禁止body的滚动条
一般禁止body滚动的做法就是设置overflow:hidden. 但是很奇怪的发现在移动端浏览器和微信浏览器上这个不起作用,然后我分析了我的写法,就是在body上加了一个class去定义属性,然后改 ...
- '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error
'0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error 异常现象 ### Cause: java.sql.SQ ...
- usr/include/dispatch - dispatch_source
博文一部分摘自:Parse分析,以下简称博文1(LeanCloud工程师针对Parse使用GCD的分析) 博文一部分摘自:GCD入门,以下简称博文2 建议先了解一下:BSD基础知识 在Dispatch ...
- <<< java如何调用系统程序
通过 java.lang.Runtime 类用操作系统命令 然后调用run.exec()进程来执行命令程序 cmd /c dir 是执行完dir命令后关闭命令窗口. cmd /k dir 是执行完di ...