B - The Blocks Problem UVA - 101
来源:互联网 发布:白茶女装淘宝旗舰店 编辑:程序博客网 时间:2024/06/11 11:29
看不懂题目是硬伤,直到讲题知道意思后才勉强做出。。
//1.move a onto b,把a和b上面的方块都放回原来位置,然后把a放到b上面;
//2.move a over b,把a上面的放回原处,然后把a放在b所在的方块堆的上面;
//3.pile a onto b,把b上面的放回原来位置,然后把a和a上面的方块整体放到b上面;
//4.pile a over b,把a和a上面的方块整体放到b所在堆的上面。
//move 和 onto 后面是归位,判断后再移动
所以不用分四种讨论,可以和在一起
注意resize的用法
#include <bits/stdc++.h>using namespace std;int n;vector<int> arr[30];void find(int a, int&p, int&h){ for(p = 0; p < n; p++) for(h = 0; h < arr[p].size(); h++) if(arr[p][h] == a) return;}void guiwei(int p, int h){ for(int i = h+1; i < arr[p].size(); i++) { int a = arr[p][i]; arr[a].push_back(a); } arr[p].resize(h+1);//resize是保留下标0~h;后面的清空 // cout<<1<<endl;}void yidong(int pa, int ha, int pb){ for(int i = ha; i < arr[pa].size(); i++) arr[pb].push_back(arr[pa][i]); arr[pa].resize(ha);// cout<<1<<endl;}int main(){ while(scanf("%d", &n) != EOF) { int a, b; string s1, s2; for(int i = 0; i < n; i++) arr[i].push_back(i); while(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(s1 == "move") guiwei(pa, ha); if(s2 == "onto") guiwei(pb, hb); yidong(pa, ha, pb); } for(int i = 0; i < n; i++) { printf("%d:", i); for(int j = 0; j < arr[i].size(); j++) printf(" %d", arr[i][j]); printf("\n"); } }}
0 0
- B - 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
- 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
- 【机器学习】人像识别(二)——PCA降维
- Python Selenium 常用方法总结
- 如何一步一步用DDD设计一个电商网站(十三)—— 领域事件扩展
- Android Crash框架Recovery
- javaScript的调试(五)
- B - The Blocks Problem UVA - 101
- leetcode-Valid Parenthese
- leetcode: Implement Queue using Stacks
- nginx给wordpress反向代理,实现多域名访问wordpress
- 详解ajax
- NLPIR分词教程 Scala版
- wordpress优化
- 资源获取模式:Layz/Eager/Partial Acquisition
- WGAN