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 ...
随机推荐
- Angular JS的依赖注入
依赖注入是一个在组件中给出的替代了硬的组件内的编码它们的依赖关系的软件设计模式.这减轻一个组成部分,从定位的依赖,依赖配置.这有助于使组件可重用,维护和测试. AngularJS提供了一个至高无上的依 ...
- 黑马程序员——OC基础 三种特性之封装
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) 三种特性之一封装 (一)set方法和get方法 1) set方法 1&g ...
- HTML5与CSS3经典代码
1)全屏背景 body { background: url(../img/pic.jpg) no-repeat center center fixed; background-size: cover; ...
- Java HttpGet
String urlStr ="https://qyapi.weixin.qq.com/cgi-bin/gettoken?a=a&b=b"; URL url = null; ...
- 2014年6月份第2周51Aspx源码发布详情
AMX高效自定义分页控件(WinForm)源码 2014-6-9 [VS2008]2014.6.9更新内容: 1. 更改用户自定义分页控件功能布局.大大精简了调用分页自定义控件的代码,和使用系统 ...
- static成员变量与返回对象的引用
(1)用static修饰类成员变量(属性),表明该变量是静态的,无论创建多少对象,都只创建一个一个静态属性副本,也就是对象们共享同一个静态属性,这个方法常用的一个用途就是用来计算程序调用了多少次这个类 ...
- Elasticsearch学习之入门
1.什么是Elasticsearch Elasticsearch是一个基于Apche Lucene的开源实时分布式搜索和分析引擎. 2.安装 安装Elasticsearch的唯一要求是安装官方新版的j ...
- 简单C程序生成的汇编代码分析
首先给出完整的C代码: int g(int x) { ; } int f(int x) { return g(x); } int main(void) { )+; } 使用命令:gcc –S –o h ...
- 【LeetCode OJ】Recover Binary Search Tree
Problem Link: https://oj.leetcode.com/problems/recover-binary-search-tree/ We know that the inorder ...
- 黑马----JAVA迭代器详解
JAVA迭代器详解 1.Interable.Iterator和ListIterator 1)迭代器生成接口Interable,用于生成一个具体迭代器 public interface Iterable ...