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 的先后顺序都堆叠在上面. 不过上面图示的说法有一些不准确,按 ...
随机推荐
- VirtualBox装ghost XP
在win7 professional 64上安装了virtualBox4.3.14 r95030 版本,之所以要安装这个vb,是因为刚升级的vm 打开之后很占用cpu, 网上又说vb不是很占用cpu而 ...
- JS正则表达式基本概念
1.正则表达式(Regular Expression) 在JS里是RegExp 两种字义方式 1. var patt1=new RegExp("e"); 2. var patt1 ...
- hibernate的三表查询
表的关系: Cardgraderule 1:n Cardgrade Cardgrade 1:n Acardtype 实体类: public class C ...
- [MAVEN]一、maven入门之软件的下载及配置到Eclipse中
1.Maven是什么? maven是Apache.org的一个子项目,他通过一个.pom的文件(xml文件)配置可以下载此项目中需要用到的jar包.文档.源码等.Maven提供了命令行的使用方式,我们 ...
- jquery源码中的(function(window, undefined){})(window)【转】
(function( window, undefined ) {})(window);这个,为什么要将window和undefined作为参数传给它? (function( $, undefined ...
- 网页游戏外挂辅助AMF模拟通讯必备
class AMF_Post_Data { public List<byte> message; /// <summary> /// 初始化Message /// </s ...
- javaweb局部刷新-ajax异步请求springMVC显示返回的jsp内容,代替iframe
在jsp上要引入jquery <script src="<%=request.getContextPath()%>/js/jquery_ui/jquery.js" ...
- web前端各大技术都能实现什么功能
web前端各大技术都能实现什么功能 以下是孜然为你总结的web前端开发你必须要一项一项掌握的技术:Html.css.ajax.jquery.extjs.JavaScript,今天为你详细解读他们各自都 ...
- C# 的TCP Socket (同步方式)
简单的c# TCP通讯(TcpListener) C# 的TCP Socket (同步方式) C# 的TCP Socket (异步方式) C# 的tcp Socket设置自定义超时时间 C# TCP ...
- Ubuntu下的MySQL安装
<1>安装mysql-server sudo apt-get update sudo apt-get install mysql-server mysql-client <2> ...