UVA 101
题意:四种操作把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的更多相关文章
- UVa 101 The Blocks Problem Vector基本操作
UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that inst ...
- 木块问题(The Blocks Problem,Uva 101)
不定长数组:vector vector就是一个不定长数组.不仅如此,它把一些常用操作“封装”在了vector类型内部. 例如,若a是一个vector,可以用a.size( )读取它的大小,a.resi ...
- Uva 101 -- the block problem
Uva 101 the block problem 题目大意: 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置.现对这些木块进行操作,操作分为四种. 1.move a o ...
- UVa 101 - The Blocks Problem(积木问题,指令操作)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...
- UVa 101 The Blocks Problem
题意:给出从左到右放置的n块木块(从0开始编号),再给出四种操作,再给出相应的操作,输出操作结束后每一堆木块的情况. 学习的紫书,因为每一堆的木块数是在发生变化的,所以用vector. 然后就是模拟几 ...
- UVa 101 (模拟) The Blocks Problem
题意: 有n个木块及n个木块堆,初始状态是第i个木块在第i个木块堆上.对应有四种操作,然后输出最终状态. 分析: 用一个vector<int>模拟一个木块堆,进行相应操作即可. #incl ...
- uva 101 by sixleaves
这是一道很好的模拟题,用vector<int> p[maxn],建立模型,映射为maxn个堆.主要要掌握vector模拟堆操作的简单方法.接下来得思路是自顶向下的方式,逐步完善程序.首先根 ...
- UVA 101 vector
题目链接 白书上的例题,关于vector的使用.不定长数组vector,类型内部封装了一些常用操作.vector就像一个二维数组,只有第一维的大小是固定的,可以像数组一样访问到其中的每一个元素. ve ...
随机推荐
- [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys
错误原因在于出现相同内容. 原写为: <li ng-repeat="log in logs" scroll-down> {{log}}</li> 改写为: ...
- JDK安装与环境变量配置
1.安装JDK 选择安装目录 安装过程中会出现两次 安装提示 .第一次是安装 jdk ,第二次是安装 jre .建议两个都安装在同一个java文件夹中的不同文件夹中.(不能都安装在java文件夹的根目 ...
- JS 笔记(一)
1. 页面引入 1) 标签直接引入脚本(推荐): <script type="text/javascript"> 脚本语言 </script> 2) 标签引 ...
- 移动混合开发之android文件管理-->flexbox,webFont。
增加操作栏,使用felxbox居中,felx相关参考网址:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html 使用webFont添加图标, ...
- js的异常捕获
try{ ...some code... }catch(e){ ...some code... //处理错误 throw(e.name); //抛出异常 }finally{<BR> // ...
- C++中explicit关键字的使用
看书看到了explicit关键字,就来做个笔记,讲得比较明白,比较浅. 在C++中,我们有时可以将构造函数用作自动类型转换函数.但这种自动特性并非总是合乎要求的,有时会导致意外的类型转换,因此,C++ ...
- linux内核分析——扒开系统调用的三层皮(上)
20135125陈智威 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 系统调用 ...
- 第6章 第一个Linux驱动程序:统计单词个数
编写一个Linux的一般步骤: 第1步:建立Linux驱动骨架(装载和卸载Linux驱动) 第2步:注册和注销设备文件 第3步:指定和驱动相关的信息 第4步:指定回调函数 第5步:编写业务逻辑 第6步 ...
- asp.net中的GridView控件的部分知识点
<PagerTemplate> <br /> <asp:Label ID="lblPage" runat="server" Tex ...
- ES5 对数组方法的扩展 以及 正则表达式
ES5 对数组的扩展 forEach map some every indexOf lastIndexOf forEach 与 map 语法: 数组.forEach(function ( v, i ) ...