【例题5-2 UVA - 101】The Blocks Problem
2017-10-12 12:08
369 查看
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
用vector模拟就好。
resize的时候,只是把多余的清理掉。
原先的不会变的。
【错的次数】
在这里输入错的次数
【反思】
在这里输入反思
【代码】
#include <bits/stdc++.h> using namespace std; const int N = 30; string s1, s2; int n, a, b; vector <int> v ; void get_sta(int a, int &p, int &h) { for (int i = 0; i < n; i++) { int len = v[i].size(); for (int j = 0;j < len;j++) if (v[i][j] == a) { p = i, h = j; return; } } } void clear(int p, int h) { int lenv = v[p].size(); for (int j = h + 1; j < lenv; j++) v[v[p][j]].push_back(v[p][j]); v[p].resize(h + 1); } void add(int p1, int h1, int p2) { int lenv = v[p1].size(); for (int j = h1; j < lenv; j++) v[p2].push_back(v[p1][j]); v[p1].resize(h1); } int main() { //freopen("F:\\rush.txt", "r", stdin); scanf("%d", &n); for (int i = 0; i < n; i++) v[i].push_back(i); while (cin >> s1) { if (s1 == "quit") break; cin >> a >> s2 >> b; int p1, h1, p2, h2; get_sta(a, p1, h1); get_sta(b, p2, h2); if (p1 == p2) continue; if (s1 == "move") clear(p1, h1); if (s2 == "onto") clear(p2, h2); add(p1,h1,p2); } for (int i = 0; i < n; i++) { printf("%d:",i); int len = v[i].size(); for (int j = 0; j < len; j++) printf(" %d", v[i][j]); puts(""); } return 0; }
相关文章推荐
- UVA 101 The blocks problem 例题整理
- 例题5-2 UVa101 The Blocks Problem(STL:vector)
- 《算法竞赛入门经典2ndEdition 》例题5-2 木块问题(The Blocks Problem, Uva101)
- UVA101 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
- POJ 1208 The Blocks Problem (UVA 101)
- 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