POJ 1208 The Blocks Problem
来源:互联网 发布:全球互联网大会 知乎 编辑:程序博客网 时间:2024/06/06 08:57
#include<iostream>#include<cstdio>#include<vector>#include<string>using namespace std;const int maxn=30;int n;vector<int> pile[maxn];void find(int a,int &p,int &h){ for(p=0;p<n;p++) for(h=0;h<pile[p].size();h++) if(a==pile[p][h]) return ;}void clear_above(int p,int h){ for(int j=h+1;j<pile[p].size();j++) { int b=pile[p][j]; pile[b].push_back(b); } pile[p].resize(h+1);}void pile_onto(int p,int h,int p2){ for(int j=h;j<pile[p].size();j++) pile[p2].push_back(pile[p][j]); 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; string s1,s2; scanf("%d",&n); for(int i=0;i<n;i++) pile[i].push_back(i); while(1) { cin>>s1; if(s1=="quit") break; cin>>a>>s2>>b; int pa, pb, ha, hb; find(a, pa, ha); find(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;}
0 0
- poj 1208 The Blocks Problem
- POJ 1208 The Blocks Problem
- POJ-1208-The Blocks Problem
- poj 1208 The Blocks Problem
- POJ 1208 The Blocks Problem
- POJ 1208 The Blocks Problem
- POJ 1208 The Blocks Problem
- POJ 1208 The Blocks Problem [模拟]
- POJ 1208 The Blocks Problem (UVA 101)
- POJ 1208 The Blocks Problem(模拟)
- POJ-模拟-1208 The Blocks Problem
- B -- POJ 1208 The Blocks Problem
- POJ 1208 The Blocks Problem 链表
- 1125 POJ#1208 The Blocks Problem
- POJ 1208 The Blocks Problem 简单栈模拟
- POJ 1208 The Blocks Problem 栈模拟 练STL
- uva-101 && poj 1208 The Blocks Problem (模拟栈)
- poj 1208 The Blocks Problem 模拟+vector的使用
- android 类型
- 20非常有用的Java程序片段
- Aurora编辑LaTex公式基本用法教程
- C++运算符重载
- 程序员的520表达方式
- POJ 1208 The Blocks Problem
- C++ 文件输入输出(四)
- Linux下进程的通信方式: 有名管道(命名管道)
- Python基础笔记
- Hibernate初探【3】Session中get()和load()的区别
- YTU 2344: 先序遍历二叉树
- 漂亮的JAVABEAN与TEXT传递
- 训练3 习题13
- 空基类优化EBO之深度探索