POJ-1208(The Blocks Problems)
题目链接: POJ - 1028
notice :
Any command in which a = b or in which a and b are in the same stack of
blocks is an illegal command. All illegal commands should be ignored and
should have no affect on the configuration of blocks.
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;const int MAXN = 27;const char MOVE[] = "move";
const char PILE[] = "pile";
const char OVER[] = "over";
const char ONTO[] = "onto";
const char QUIT[] = "quit";
vector<int> Stack[MAXN];
char cmd1[100], cmd2[100];
struct _Position{int stack;int pos;_Position(int s, int p):pos(p), stack(s){}
};
void init()
{for(int i = 0; i < MAXN; ++i)Stack[i].clear(), Stack[i].push_back(i);
}void Print(int n)
{for(int i = 0; i < n; ++i){int len = Stack[i].size();printf("%d:", i);if(len != 0){for(int j = 0; j < len; ++j){printf(" %d", Stack[i][j]);}}printf("\n");}
}_Position findBlock(int n, int x)
{for(int i = 0; i < n; ++i)for(int j = 0; j < Stack[i].size(); ++j)if(x == Stack[i][j]) return _Position(i, j);
}void move(_Position pa, _Position pb, char cmd2[])
{//cout << pa.stack << "--" << pa.pos <<endl;vector<int>::iterator itas = Stack[pa.stack].begin(), itbs = Stack[pb.stack].begin();vector<int>::iterator itae = Stack[pa.stack].end(), itbe = Stack[pb.stack].end();if(strcmp(cmd2, ONTO) == 0){Stack[pb.stack].insert(itbs + pb.pos + 1, Stack[pa.stack][pa.pos]);}else{Stack[pb.stack].push_back(Stack[pa.stack][pa.pos]);}Stack[pa.stack].erase(itas + pa.pos, itas + pa.pos + 1);
}void pile(_Position pa, _Position pb, char cmd2[])
{//cout << pa.stack << "--" << pa.pos <<endl;vector<int>::iterator itas = Stack[pa.stack].begin(), itbs = Stack[pb.stack].begin();vector<int>::iterator itae = Stack[pa.stack].end(), itbe = Stack[pb.stack].end();if(strcmp(cmd2, ONTO) == 0){Stack[pb.stack].insert(itbs + pb.pos, itas + pa.pos, itae);}else{Stack[pb.stack].insert(itbe, itas + pa.pos, itae);}Stack[pa.stack].erase(itas + pa.pos, itae);
}int main()
{int n, a, b;while(cin >> n){init();while(cin >> cmd1){if(strcmp(cmd1, QUIT) == 0) break;cin >> a >> cmd2 >> b;_Position pa = findBlock(n, a);_Position pb = findBlock(n, b);if(pa.stack == pb.stack) continue;if(strcmp(cmd1, MOVE) == 0) move(pa, pb, cmd2);else pile(pa, pb, cmd2);}Print(n);}return 0;
}
POJ-1208(The Blocks Problems)相关推荐
- the blocks problem(uva 101 or poj 1208)
题目描述见:uva 101 or poj 1208 关键在于彻底理解题目中搬积木的几个命令的含义,见具体分析 如果还不能理解题意,那么找一个正确通过的代码,编译并输入测试数据,查看其每一个命令的执行情 ...
- poj 1208 Web Navigation(堆栈操作)
一.Description Standard web browsers contain features to move backward and forward among the pages re ...
- POJ前面的题目算法思路【转】
1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...
- POJ 动态规划题目列表
1.这份列表当然不是我原创的,从文库里下载了一份,放到这里便于自己浏览和查找题目. ※最近更新:Poj斜率优化题目 1180,2018,3709 列表一:经典题目题号: 容易: 1018, 1050 ...
- POJ 超详细分类
POJ 各题算法 1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 ...
- poj动态规划经典题目
列表一:经典题目题号: 容易: 1018, 1050, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1 ...
- 【转】别人整理的DP大全
为什么80%的码农都做不了架构师?>>> 动态规划 动态规划 容易: 1018 , 1050 , 1083 , 1088 , 1125 , 1143 , 1157 , 1163 ...
- ICPC训练联盟2021寒假冬令营(6)_2021.01.25_笔记
文章目录 试题链接 学习笔记 - C++ STL 简介 STL容器实验 序列式容器 关联式容器 集合容器 A - The Blocks Problem (POJ 1208, UVA 101) 中文释义 ...
- 解题报告(四)生成函数(ACM/ OI)
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...
最新文章
- 区块链技术到底有啥用?
- 联机事务处理OLTP(on-line transaction processing)和联机分析处理OLAP(On-Line Analytical Processing)...
- Window下mysql的安装
- Spark系列(八)Worker工作原理
- Halcon初学者知识【15】图像的定义域Domain
- gui linux 桌面应用,吃掉Linux开发者,WSL支持GUI应用
- VisualStudioCode 中设置中文语言【图文教程】
- qt开发环境 - c++之输入,输出,名字空间定义,名字空间指令,名字空间声明
- mysql主从复制 lvs+ keepalived
- 《Python Cookbook 3rd》笔记(3.4):二、八、十六进制整数
- MySQL数据查询新人须知
- 大型云原生项目在数字化企业落地过程解密 1
- Go Hack 2017 报名开启:十月魔都约一场 Go 语言烧脑之战
- 使用wps插件,实现word转PDF
- SPSS调节效应分析插件 v1.1.1
- 福大软工1816 · 第四次作业 - 团队展示
- oracle delete一直没有结束怎么办 教你跟踪delete和rollback进度之-《delete跟踪篇》
- 虚拟机linux开启端口 与阿里云服务器开启端口的方法
- 2021中国大学生程序设计竞赛(CCPC)- 网络选拔赛(重赛) Jumping Monkey(并查集,逆向考虑)
- 三相异步电机的平衡方程式