UVA 101 The Blocks Problem
来源:互联网 发布:手机淘宝怎么看信誉度 编辑:程序博客网 时间:2024/06/07 02:38
题目
木块问题
分析
每一摞木块是栈,每次的移动不过出他的栈入她的栈。
思路
模仿的代码,使用vector
。
代码
#include <cstdio>#include <vector>using std::vector;const int MAXN = 30;int n;vector<int> block[MAXN];void find(int a, int& p, int& h){ for (p = 0; p < n; p++) for (h = 0; h < block[p].size(); h++) if (block[p][h] == a) return;}void clear(int p, int h){ for (int i = h+1; i < block[p].size(); i++) { int b = block[p][i]; block[b].push_back(b); } block[p].resize(h+1);}void pile(int p, int h, int p2){ for (int i = h; i < block[p].size(); i++) block[p2].push_back(block[p][i]); block[p].resize(h);}int main(){ int a, b, ha, hb, pa, pb; char s1[5], s2[5]; scanf("%d", &n); for (int i = 0; i < n; i++) block[i].push_back(i); while (scanf("%s %d %s %d", s1, &a, s2, &b) == 4){ find(a, pa, ha); find(b, pb, hb); if (pa == pb) continue; if (s2[1] == 'n') clear(pb, hb); if (s1[0] == 'm') clear(pa, ha); pile(pa, ha, pb); } for (int i = 0; i < n; i++) { printf("%d:", i); for (int j = 0; j < block[i].size(); j++) printf(" %d", block[i][j]); printf("\n"); } return 0;}
0 0
- uva 101 the blocks problem
- uva 101 the blocks problem
- UVa 101 The Blocks Problem
- uva 101 - The Blocks Problem
- uva 101 - The Blocks Problem
- UVa 101 - The Blocks Problem
- uva 101 - The Blocks Problem
- UVa 101 - The Blocks Problem
- Uva-101-The Blocks Problem
- Uva 101 - The Blocks Problem
- uva 101 The Blocks Problem
- UVa 101 - The Blocks Problem
- uva 101 - The Blocks Problem
- UVA 101 The Blocks Problem
- uva 101 - The Blocks Problem
- UVa 101 The Blocks Problem
- UVa 101 - The Blocks Problem
- uva 101 The Blocks Problem
- 来京学习第15天(前2天是周末)
- [BZOJ1607] [Usaco2008 Dec]Patting Heads 轻拍牛头
- 【Unity3D游戏开发】NGUI之DrawCall数量 (四)
- 无限互联的日子——连载一
- 天才的大三暑假修行之旅.表面着色器(总结)
- UVA 101 The Blocks Problem
- bearlon的HTML学习笔记1
- 设计模式(15) - 备忘录模式
- oracle启动脚本——window
- UVA 133 The Dole Queue
- 如何成为SAP行业专家
- 表达式计算 .
- 安卓sqlite数据库加速写入
- 3.03-while练习2