题意:四种操作把a和b所在的数字移动。

lrj的思想很好。首先找到共同点。然后不必写四种操作。其次理解vector的方便。

#include<iostream>
#include<cstdio>
#include<vector> using namespace std; const int maxn = ;
int n;
vector<int>pile[maxn]; void find_back(int a,int &p,int &h)
{
for(p = ;p < n; p++){
for(h = ;h < pile[p].size(); h++){
if(pile[p][h] == a) return ;
}
}
} void clear_above(int p,int h)
{
for(int i = h+;i < pile[p].size(); i++){
int b = pile[p][i];
pile[b].push_back(b);
}
pile[p].resize(h+);
} void pile_onto(int p,int h,int p2)
{
for(int i = h;i < pile[p].size(); i++){
pile[p2].push_back(pile[p][i]);
}
pile[p].resize(h);
} int main()
{
//freopen("in.txt","r",stdin);
int a,b;
cin>>n;
string s1,s2;
for(int i = ;i < n; i++)
pile[i].push_back(i);
while(cin>>s1>>a>>s2>>b){
int pa,ha,pb,hb;
find_back(a,pa,ha);
find_back(b,pb,hb);
if(pa == pb)
continue;
if(s2 == "onto")
clear_above(pb,hb);
if(s1 == "move")
clear_above(pa,ha);
pile_onto(pa,ha,pb);
}
for(int i = ;i < n; i++){
printf("%d:",i);
for(int j = ;j < pile[i].size(); j++){
printf(" %d",pile[i][j]);
}
printf("\n");
}
return ;
}

UVA 101的更多相关文章

  1. UVa 101 The Blocks Problem Vector基本操作

    UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that inst ...

  2. 木块问题(The Blocks Problem,Uva 101)

    不定长数组:vector vector就是一个不定长数组.不仅如此,它把一些常用操作“封装”在了vector类型内部. 例如,若a是一个vector,可以用a.size( )读取它的大小,a.resi ...

  3. Uva 101 -- the block problem

    Uva 101 the block problem 题目大意: 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置.现对这些木块进行操作,操作分为四种. 1.move a o ...

  4. UVa 101 - The Blocks Problem(积木问题,指令操作)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  5. uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟

    挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...

  6. UVa 101 The Blocks Problem

    题意:给出从左到右放置的n块木块(从0开始编号),再给出四种操作,再给出相应的操作,输出操作结束后每一堆木块的情况. 学习的紫书,因为每一堆的木块数是在发生变化的,所以用vector. 然后就是模拟几 ...

  7. UVa 101 (模拟) The Blocks Problem

    题意: 有n个木块及n个木块堆,初始状态是第i个木块在第i个木块堆上.对应有四种操作,然后输出最终状态. 分析: 用一个vector<int>模拟一个木块堆,进行相应操作即可. #incl ...

  8. uva 101 by sixleaves

    这是一道很好的模拟题,用vector<int> p[maxn],建立模型,映射为maxn个堆.主要要掌握vector模拟堆操作的简单方法.接下来得思路是自顶向下的方式,逐步完善程序.首先根 ...

  9. UVA 101 vector

    题目链接 白书上的例题,关于vector的使用.不定长数组vector,类型内部封装了一些常用操作.vector就像一个二维数组,只有第一维的大小是固定的,可以像数组一样访问到其中的每一个元素. ve ...

随机推荐

  1. 火狐和IE浏览器的兼容问题汇总

    1.window.event code=(navigator.appName="Netscape")?event.which:event.keycode; 2.event.x mx ...

  2. linux自动更新代码,打包发布

    1.安装svn yum install subversion 2.安装 maven 下载:百度云盘地址为 http://pan.baidu.com/s/1nuKQGjv 解压 tar -zxvf ap ...

  3. 搭建Android开发环境简要步骤

    (一)安装JDK JDK下载地址 http://www.oracle.com/technetwork/java/javase/downloads/index.html 在Linux终端输入如下命令,设 ...

  4. 从C++转向Java的第一课

    序:计算机语言的学习,最快捷的方法是从一种语言映射到另一种语言.Java和C++作为最通用的面相对象高级语言,不论从语法或者编程上都极具相似性和可效仿行,这里的可效仿包括——语法理解可效仿和编程规范可 ...

  5. 64位系统下找不到office 32位组件

    如果系统式64位的,而装的是32位的office软件,在运行栏中输入命令:dcomcnfg,打开组件服务管理窗口,但是却发现找不到Microsoft Excel程序, 这主要是64位系统的问题,exc ...

  6. PyCharm 3.4.1注册码

    PyCharm 3.4下载地址:http://www.jetbrains.com/pycharm/download/index.html PyCharm 3.0 注册码 PyCharm3 序列号 Li ...

  7. Codeforces Round #376 (Div. 2)

    A 模拟 #include <cstdio> #include <cstring> int Ans; ]; inline ?x:-x;} inline int Min(int ...

  8. oracle xmltype导入并解析Excel数据 (三)解析Excel数据

    包声明 create or replace package PKG_EXCEL_UTILS is -- Author: zkongbai-- Create at: 2016-07-06-- Actio ...

  9. Caffe.proto使用

    参考 http://blog.csdn.net/qq_16055159/article/details/45115359 书写.proto文件 作用:编写一个 proto 文件,定义我们程序中需要处理 ...

  10. System.Collections.Generic的各容器类的用法

    演示System.Collections.Generic的各容器类的用法. 包括:Dictionary,KeyValuePair,SortedDic tionary,SortedList,HashSe ...