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 的先后顺序都堆叠在上面. 不过上面图示的说法有一些不准确,按 ...
随机推荐
- CentOS 新增swap交换空间
在centos 6.4 64位系统中安装oracle 10g数据库软件,但由于交换空间过小导致检查不通过: 因此需要增加交换空间的大小. 第一步:在opt目录下新建swap交换文件,并设置其大小为2G ...
- JS组件系列——开源免费图表组件:Chart.js
前言:最近被开源免费得有点上火了,各种组件首先想到的就是是开源否.是否免费.是否和bootstrap风格一致.想着以后做报表肯定要用到图表组件的,于是在Bootstrap中文网上面找到了Chart.j ...
- 数学的东西(BZOJ1951)
#include <cstdio> #define LL long long LL finmo=; LL fac[][],inv[][]; LL tmp[],rev[]; LL n,g,x ...
- 软件工程(FZU2015)赛季得分榜,第10回合(alpha冲刺)
目录 第一回合 第二回合 第三回合 第四回合 第五回合 第6回合 第7回合 第8回合 第9回合 第10回合 第11回合 积分规则 积分制: 作业为10分制,练习为3分制:alpha30分: 团队项目分 ...
- MongoDB基础知识
一.Mongodb简介 Mongodb是基于分布式文件存储的数据库,用C++编写: Mongodb是nosql(not-only-sql)数据库: Mongodb '无状态模式',不用去设计,直接用, ...
- android MVC && MVP && MVVM分析和对比
相关:http://www.cnblogs.com/wytiger/p/5305087.html 出处http://blog.csdn.net/self_study,对技术感兴趣的同鞋加群544645 ...
- PHP常用框架
1.Thinkphp thinkphp是国内开发的框架,它有比较易读的手册,和大量的网上资源,所以我推荐大家首选thinkphp. 2.CodeIgniter 前一段时间我用过codeignite ...
- BZOJ 3809: Gty的二逼妹子序列
3809: Gty的二逼妹子序列 Time Limit: 80 Sec Memory Limit: 28 MBSubmit: 1387 Solved: 400[Submit][Status][Di ...
- json使用
json是存储和交换文本信息的语法,类似 XML,比 XML 更小.更快,更易解析 json 可通过 JavaScript 进行解析 json 数据可使用 AJAX 进行传输 //读取var JSON ...
- Jquery跨域访问java接口
Jquery前台代码: <script> $.getJSON("http://跨域URL/Example/text.do?jsonpCallback=?", funct ...