The Blocks Problem UVA - 101
2018-02-08 15:34
302 查看
题目链接:The Blocks Problem UVA - 101
题目:
题目:
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<iomanip> #define ll long long using namespace std; const int maxn = 30; int n; vector<int> pile[maxn]; void find_block(int &a, int &p, int &h) { for(p = 0; p < n; p++) { for(h = 0; h < pile[p].size(); h++) { if(pile[p][h] == a) return ; } } } void clear_above(int p, int h) { for(int i = h + 1; i < pile[p].size(); i++) { int b = pile[p][i]; pile[b].push_back(b); } pile[p].resize(h+1); } 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); } void print() { for(int i = 0; i < n; i++) { printf("%d:",i); for(int j = 0; j < pile[i].size(); j++) printf(" %d",pile[i][j]); printf("\n"); } } int main() { int a, b; cin >> n; string s1, s2; for(int i = 0; i < n; i++) pile[i].push_back(i); while(cin>>s1>>a>>s2>>b) { int pa, pb, ha, hb; find_block(a, pa, ha); find_block(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); } print(); return 0; }
相关文章推荐
- The Blocks Problem UVA - 101
- The Blocks Problem UVA - 101
- The Blocks Problem UVA 101 模拟
- The Blocks Problem UVA - 101
- UVA - 101 The Blocks Problem
- uva101(The Blocks Problem)-线性表+模拟
- 例题 5-2 木块问题 (The Blocks Problem) UVa 101
- The Blocks Problem ——Uva 101
- UVa 101 - The Blocks Problem
- UVA 101 (暑期-线性表-D-The Blocks Problem)
- 算法竞赛入门经典第五章例题5-2 The Blocks Problem UVA - 101
- 假期训练——The Blocks Problem UVA - 101 模拟
- UVA - 101 The Blocks Problem
- UVa101 - The Blocks Problem
- UVa 101 - The Blocks Problem
- UVA 101 The Blocks Problem(模拟)
- 木块问题(The Blocks Problem, UVa 101)
- uva 101 - The Blocks Problem(模拟)
- UVa OJ The Blocks Problem 木块问题 101
- uva 101 The Blocks Problem 解题报告