题目链接: 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)相关推荐

  1. the blocks problem(uva 101 or poj 1208)

    题目描述见:uva 101 or poj 1208 关键在于彻底理解题目中搬积木的几个命令的含义,见具体分析 如果还不能理解题意,那么找一个正确通过的代码,编译并输入测试数据,查看其每一个命令的执行情 ...

  2. poj 1208 Web Navigation(堆栈操作)

    一.Description Standard web browsers contain features to move backward and forward among the pages re ...

  3. POJ前面的题目算法思路【转】

    1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...

  4. POJ 动态规划题目列表

    1.这份列表当然不是我原创的,从文库里下载了一份,放到这里便于自己浏览和查找题目. ※最近更新:Poj斜率优化题目 1180,2018,3709 列表一:经典题目题号: 容易:  1018, 1050 ...

  5. POJ 超详细分类

    POJ 各题算法 1000    A+B Problem            送分题     49%    2005-5-7 1001    Exponentiation         高精度   ...

  6. poj动态规划经典题目

    列表一:经典题目题号: 容易: 1018, 1050, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1 ...

  7. 【转】别人整理的DP大全

    为什么80%的码农都做不了架构师?>>>    动态规划 动态规划 容易: 1018 , 1050 , 1083 , 1088 , 1125 , 1143 , 1157 , 1163 ...

  8. ICPC训练联盟2021寒假冬令营(6)_2021.01.25_笔记

    文章目录 试题链接 学习笔记 - C++ STL 简介 STL容器实验 序列式容器 关联式容器 集合容器 A - The Blocks Problem (POJ 1208, UVA 101) 中文释义 ...

  9. 解题报告(四)生成函数(ACM/ OI)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

最新文章

  1. 区块链技术到底有啥用?
  2. 联机事务处理OLTP(on-line transaction processing)和联机分析处理OLAP(On-Line Analytical Processing)...
  3. Window下mysql的安装
  4. Spark系列(八)Worker工作原理
  5. Halcon初学者知识【15】图像的定义域Domain
  6. gui linux 桌面应用,吃掉Linux开发者,WSL支持GUI应用
  7. VisualStudioCode 中设置中文语言【图文教程】
  8. qt开发环境 - c++之输入,输出,名字空间定义,名字空间指令,名字空间声明
  9. mysql主从复制 lvs+ keepalived
  10. 《Python Cookbook 3rd》笔记(3.4):二、八、十六进制整数
  11. MySQL数据查询新人须知
  12. 大型云原生项目在数字化企业落地过程解密 1
  13. Go Hack 2017 报名开启:十月魔都约一场 Go 语言烧脑之战
  14. 使用wps插件,实现word转PDF
  15. SPSS调节效应分析插件 v1.1.1
  16. 福大软工1816 · 第四次作业 - 团队展示
  17. oracle delete一直没有结束怎么办 教你跟踪delete和rollback进度之-《delete跟踪篇》
  18. 虚拟机linux开启端口 与阿里云服务器开启端口的方法
  19. 2021中国大学生程序设计竞赛(CCPC)- 网络选拔赛(重赛) Jumping Monkey(并查集,逆向考虑)
  20. 三相异步电机的平衡方程式

热门文章

  1. 服务器怎样修改盘符,服务器怎样修改盘符
  2. QPSK解调过程中的抽样判决
  3. 详解诊断数据库ODX-F
  4. Google Earth Engine (GEE)——利用两种方式进行EVI指数(含函数的两种定义方式)
  5. 论文阅读方法与技巧【教授经验】
  6. .net程序员工作两年总结
  7. 安卓drawable基本属性corners、solid、gradient、stroke、size、padding详解
  8. Linux基础命令学习——方法二(给swap分区增加500M)
  9. DNS中的正向解析与反向解析
  10. 用Python写DES加解密的常用函数