UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that instruct a robot arm in how to manipulate blocks that lie on a flat table. Initially there are nblocks on the table (numbered from 0 to n-1) with block bi…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=37   The Blocks Problem  Background Many areas of Computer Science use simple, abstract domains for both analytical and empiric…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=835&page=show_problem&problem=37 木块问题,模拟堆的操作.每个堆的高度不确定,用vector来做很合适(vector动态). 本题模拟四个操作: 1.move a onto b:把a和b上方的木块全部放回原来的堆,然后把a摞在b上面 2.move a over b:把a上方的木块全部放回…
题意:给出从左到右放置的n块木块(从0开始编号),再给出四种操作,再给出相应的操作,输出操作结束后每一堆木块的情况. 学习的紫书,因为每一堆的木块数是在发生变化的,所以用vector. 然后就是模拟几种操作 学习了这个& 在这个函数里面,find_block(inta,int &p,int&h) 紫书上写的注释是“找出木块a所在的pile和height,以引用的形式返回调用者” 最开始不明白= =然后写了一个小的程序试验了一下 #include<iostream> #i…
题目:给你n个方块,有四种操作: .move a onto b,把a和b上面的方块都放回原来位置,然后把a放到b上面: .move a over b,把a上面的放回原处,然后把a放在b所在的方块堆的上面: .pile a onto b,把b上面的放回原来位置,然后把a和a上面的方块整体放到b上面: .pile a over b,把a和a上面的方块整体放到b所在堆的上面. 分析:模拟,数据结构.观察操作,如果是move就是先把a上面的还原,如果是onto就是先把b上面的还原. 然后,就是移动一堆到…
Uva 101 the block problem 题目大意: 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置.现对这些木块进行操作,操作分为四种. 1.move a onto b:把木块a.b上的木块放回各自的原位,再把a放到b上: 2.move a over b:把a上的木块放回各自的原位,再把a发到含b的堆上: 3.pile a onto b:把b上的木块放回各自的原位,再把a连同a上的木块移到b上: 4.pile a over b:把a连同a上木块移到含b的…
http://poj.org/problem?id=1208 晚点仔细看 https://blog.csdn.net/yxz8102/article/details/53098575 #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<stdlib.h> #include<algorithm> #include<que…
终于AC了,这道题目去年寒假卡得我要死,最后一气之下就不做了...想想居然一年之久了,我本来都快忘了这道题了,最近发现白书的奥秘,觉得刘汝佳的题目真的相当练思维以及对代码的操作,决定又刷起题目来,这时候才想起这道题. 用栈进行模拟堆砖块,用个rec[]数组记录其现在所在的栈号,比较麻烦的是pile 操作,为了把a以及a以上的所有砖块都以原秩序放置于b砖块顶端,我用了个临时的栈进行存贮,然后再一个一个放到b栈上面..这样就不会破坏秩序..但是感觉这样做挺耗时的,原以为通不过,结果还是通过了...2…
The Blocks Problem Descriptions:(英语就不说了,直接上翻译吧) 初始时从左到右有n个木块,编号为0~n-1,要求实现下列四种操作: move a onto b: 把a和b上方的木块全部放回初始的位置,然后把a放到b上面 move a over b: 把a上方的木块全部放回初始的位置,然后把a放在b所在木块堆的最上方 pile a onto b: 把b上方的木块部放回初始的位置,然后把a和a上面所有的木块整体放到b上面 pile a over b: 把a和a上面所有…
挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: move a onto b  在将a搬到b上之前,先把a和b上的积木放回原來的位置 move a over b在将a搬到b所在的那堆积木上前,先把a上的积木放回原來的位罝 pile a onto b 将包括a本身和上方的积木一起放到b上,在放之前b上方的积木放回原来的位置 pile a over b 将包括a本…