Uva 101(vector的使用)木块问题
来源:互联网 发布:求一款网络休闲游戏 编辑:程序博客网 时间:2024/06/10 09:31
//vctor的使用,用函数封装一个操作还是蛮舒服的#include<cstdio>#include<iostream>#include<vector>#include<map>using namespace std;vector<int> a[30];char s[10];int n,u,v;void find(int num,int& x,int& h){ //找到num的位置 for(int i=0; i<n; ++i) for(int j=0; j<a[i].size(); ++j) if(a[i][j]==num) { x=i,h=j; return; }}void clear_above(int x,int h){ //将x,h以上的放回原位 for(int i=h+1; i<a[x].size(); ++i) a[a[x][i]].push_back(a[x][i]); a[x].resize(h+1);//相当于把h+1以上的全都去了}void push(int y,int x,int h){ //将x,h及以上的全都放到y上 for(int i=h; i<a[x].size(); ++i) a[y].push_back(a[x][i]); a[x].resize(h);}void print(){ for(int i=0; i<n; ++i) { printf("%d:",i); for(int j=0; j<a[i].size(); ++j) printf(" %d",a[i][j]); puts(""); }}int main(){ scanf("%d",&n); for(int i=0; i<n; ++i) a[i].push_back(i); while(scanf("%s",s)&&s[0]!='q') { if(s[0]=='m') { scanf("%d%s%d",&u,s,&v); int x1,h1,x2,h2; find(u,x1,h1); find(v,x2,h2); if(x1==x2) continue; if(s[1]=='n') { clear_above(x1,h1); clear_above(x2,h2); push(x2,x1,h1); } else { clear_above(x1,h1); push(x2,x1,h1); } } else { scanf("%d%s%d",&u,s,&v); int x1,h1,x2,h2; find(u,x1,h1); find(v,x2,h2); if(x1==x2) continue; if(s[1]=='n') { clear_above(x2,h2); push(x2,x1,h1); } else push(x2,x1,h1); } } print(); return 0;}
阅读全文
1 0
- Uva 101(vector的使用)木块问题
- 木块问题(vector)-UVa 101
- 紫书章五例二 木块问题 UVA 101(vector)
- UVA(木块问题)101
- 101UVa木块问题
- Uva 101 the block problem 木块问题(算法竞赛经典入门)STL vector
- 木块问题 (using std::vector) UVA
- 例题:木块问题(UVa 101)
- P2784 木块问题 本该用vector的.....
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
- Uva 101:The Blocks Problem(木块问题)
- uva 101 木块问题 The Blocks Problem
- The Blocks Problem UVA 101 木块问题
- 木块问题(The Blocks Problem, UVa 101)
- uva 101木块游戏
- UVA 101 木块
- 例题 5-2 木块问题 (The Blocks Problem) UVa 101
- 例题5-2 UVA 101 The Blocks Problems 木块问题
- css 技巧总结
- 康拓展开
- C语言之动态内存分配
- bzoj 4952: E
- if、while、random
- Uva 101(vector的使用)木块问题
- 关于static关键字以及静态方法和属性的说明
- PXE + KickStart实现全自动化系统安装
- 阿里云
- 17、合并两个排序链表
- STM32 Tutorial: #2 Light up LEDs
- hdu 6048 Puzzle 思维(8数码问题
- knockout.mapping插件的ko.mapping.fromJS两种不同调用的区别
- Java日志框架梳理-SLF4J+logback