UVA 101 The Blocks Problem
来源:互联网 发布:调音量软件下载 编辑:程序博客网 时间:2024/05/22 06:40
UVA 101 The Blocks Problem
题目大意:
move a onto b:找到a和b所在列,把a和b数字以上的数字全部放回原位置,然后把a放到b所在的列头
move a over b:找到a所在列,把a数字以上的数字全部放回原位置,然后把a放到b所在的列头
pile a onto b:把b所在列b数字以上的数字全部放回原位置,然后把a和a以上的数字全放到b所在列列头
pile a over b:把a和a以上的数字全放到b所在列列头
解题思路:用栈的思想构造数组来解决
#include <stdio.h>#include <iostream>using namespace std;int s[100][100], oa[100]; // 栈int num[100], ob;int top[100]; //头指针void move(int a, int x) { for(; s[x][top[x]-1] != a; top[x]--) { int t = s[x][top[x]-1]; s[t][top[t]] = t; num[t] = t; top[t]++; }}void pile(int a, int x) { for(; s[x][top[x]-1] != a; top[x]--) { oa[ob] = s[x][top[x]-1]; ob++; }}void over(int b, int y) { for(; ob >= 0; ob--) { s[y][top[y]] = oa[ob]; top[y]++; num[oa[ob]] = y; }}int main() { int n; while(scanf("%d", &n) != EOF) { getchar(); for(int i = 0; i < n; i++) { s[i][0] = i; num[i] = i; top[i] = 1; } char com1[100], com2[100]; int a, b; while(scanf("%s", com1) && com1[0] != 'q') { scanf("%d%s%d", &a, com2, &b); int x = num[a], y = num[b]; if(x == y) continue; if(com1[0] == 'm') { ob = 0; move(a, x); oa[ob] = a; top[x]--; } else if(com1[0] == 'p') { ob = 0; pile(a, x); oa[ob] = a; top[x]--; } if(com2[1] == 'n') { move(b, y); over(b, y); } else if(com2[1] == 'v') over(b, y); } for(int i = 0; i < n; i++) { printf("%d:", i); for(int j = 0; j < top[i]; j++) { printf(" %d", s[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
- java枚举使用详解
- service redis does not support chkconfig的解决办法
- Java常用排序算法/程序员必须掌握的8大排序算法
- Opencv+C++之身份证识别(一)
- Override与Overload
- UVA 101 The Blocks Problem
- JSP的内置对象
- Python 科学计算 -- Numpy
- Python Web 框架
- 《intel汇编语言程序设计》 第一章记录
- WebRTC-百度
- Android 自定义RecyclerView 实现真正的Gallery效果
- Java实现多文件压缩和解压缩代码(未测试)
- Qt之QSS(白色靓丽)