#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 30;
vector<int> pile[maxn];
int n;
//查找a所在的pile和height;
void Find_pile(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_pile(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 a, int h, int b)
{for (int i = h; i < pile[a].size(); i++){pile[b].push_back(pile[a][i]);}pile[a].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]);cout << endl;}}
int main()
{cin >> n;string s1, s2;int a, b;for (int i =0; i < n; i++) pile[i].push_back(i);while(cin >> s1 >> a >> s2 >> b){int pa, ha, pb, hb;Find_pile(a, pa, ha);Find_pile(b, pb, hb);if(pa == pb) continue;if(s2 == "onto") clear_pile(pb, hb);if(s1 == "move") clear_pile(pa, ha);pile_onto(pa, ha, pb);}print();return 0;
}
详细解决方案
Uva 101 The Blocks Problem
热度:79 发布时间:2023-11-20 06:07:49.0
相关解决方案
- 'Update Progress' has encountered a problem An internal error has occurred解决方案
- 'Update Progress' has encountered a problem An internal error has occurred解决方案
- 每日背熟一句英语(7)The problem I'm running into is that the window is opening up modal
- 每日背熟一句英语(14)You don't have to feel very sorry for your problem
- 每天背熟一句英语(7)The problem I'm running into is that the window is opening up modal.解决方案
- 每天背熟一句英语(14)You don't have to feel very sorry for your problem.该怎么解决
- TortoiseSVN失误:svn there has been a problem contacting the server
- 这道题关于check log shipping and find out the problem,该如何处理
- 修理android获取ip地址失败 Fix Obtaining IP Address Android WiFi Problem
- 【CodeCraft赛事】Problem 3——INVESCAPE (迷宫BFS)
- [求助]a problem, please help
- one problem
- J2ME项目保存出错 Problem Occurred
- a+b problem
- a+b problem
- the problem i don`t understand
- [求助] heap sort 排序算法(堆排序) problem
- 一道ACM题:The Counting Problem
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1198&& I can do it
- http://acm.uestc.edu.cn/problem.php?pid=1784&&
- eclise导入已存在工程报 Faceted Project Problem 异常
- javascript problem,该怎么处理
- The problem is choice.解决办法
- <h2>Struts Problem Report</h2>该如何解决
- SSH整合出错 Struts Problem Report?该如何处理
- javax.servlet.jsp.JspException: TableTag Problem,该如何处理
- eclipse导入已存在工程报 Faceted Project Problem 异常
- ivy:rosolve io problem while parsing ivy file Path contains invalid character:该如何解决
- eclipse启动时,揭示'dashboard' has encountered a problem
- MyEclipse总是弹出“Building workspace has encountered a problem. Errors during build.该怎么处理