参考:https://blog.csdn.net/yxz8102/article/details/53098575

https://www.cnblogs.com/tanjuntao/p/8678927.html

 #include <iostream>
#include <cstdio>
#include <vector>
#define N 30
using namespace std;
int n,a,b;
string s,sa;
vector<int> v[N];
void init()
{
int i;
for (i=;i<N;i++)
{
v[i].clear();
v[i].push_back(i);
}
}
void test()
{
cout<<s<<a<<sa<<b<<endl;
}
bool judge(int& ba,int& bb,int& ha,int& hb)//判断输入合法性 ,地址传参
{
int i,j;
for (i=;i<n;i++)
{
for (j=;j<v[i].size();j++)
{
if (v[i][j]==a)
{
ba=i;
ha=j;
}
if (v[i][j]==b)
{
bb=i;
hb=j;
}
}
}
if (ba==bb)
{
return true;
}
else
{
return false;
}
}
void clear(int block,int high)
{
int i;
for (i=high+;i<v[block].size();i++)
{
int t=v[block][i];
v[t].push_back(t);
}
v[block].resize(high+);
}
void pile(int pba,int pbb,int pha,int phb)
{
int i;
for (i=pha;i<v[pba].size();i++)
{
v[pbb].push_back(v[pba][i]);
}
v[pba].resize(pha);//重设长度会删除后面元素~
}
void show()
{
int i;
for (i=;i<n;i++)
{
printf("%d:",i);
for (int j=;j<v[i].size();j++)
{
printf(" %d",v[i][j]);//依据方便实用printf,cout!!!
}
printf("\n");
}
}
int main()
{
while (scanf("%d",&n)!=EOF)
{
int i;
init();
while (cin>>s)
{
if (s=="quit")
{
break;
}
cin>>a>>sa>>b;
int ba,bb,ha,hb;//ba为a的堆,ha为a在堆的高度
if (judge(ba,bb,ha,hb))//多用传参形式,少用全局变量!!!
{
continue;
}
if (s=="move")
{
clear(ba,ha);
}
if (sa=="onto")
{
clear(bb,hb);
}
pile(ba,bb,ha,hb);
}
show();
} return ;
}

B -- POJ 1208 The Blocks Problem的更多相关文章

  1. POJ 1208 The Blocks Problem

    The Blocks Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5397   Accepted: 231 ...

  2. POJ 1208 The Blocks Problem --vector

    http://poj.org/problem?id=1208 晚点仔细看 https://blog.csdn.net/yxz8102/article/details/53098575 #include ...

  3. uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟

    挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...

  4. PKU 1208 The Blocks Problem(模拟+list应用)

    题目大意:原题链接 关键是正确理解题目意思 首先:介绍一下list容器的一些操作:参考链接 list<int> c1; c1.unique();              去重. c1.r ...

  5. The Blocks Problem(vector)

    题目链接:http://poj.org/problem?id=1208 The Blocks Problem Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  6. UVa 101 The Blocks Problem Vector基本操作

    UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that inst ...

  7. UVa 101 - The Blocks Problem(积木问题,指令操作)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  8. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  9. POJ 1208 模拟

    2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...

随机推荐

  1. C#并行库(TaskParallelLibrary)用法 z

    1. Task.Factory.StartNew(() => DoSomeWork());是异步的 下面的代码会先输出ddd,因为Task.Factory.Startnew不阻塞: var ta ...

  2. Python3基本数据类型(五、字典)

    一.定义 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号中: dic = {key: ...

  3. [转]查找问题的利器 - Git Bisect

    转自:http://gitbook.liuhui998.com/5_4.html 假设你在项目的'2.6.18'版上面工作, 但是你当前的代码(master)崩溃(crash)了. 有时解决这种问题的 ...

  4. 【[NOI2018]你的名字】

    题目 可能是一个乱搞做法,同时也跪求有人能帮我分析一下复杂度 还是先来看比较简单的\(68pts\),也就是\(l=1,r=|S|\)的情况 我们可以直接把\(S\)串和所有的\(T\)串一起建一个广 ...

  5. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A、Saving Tang Monk II 【状态搜索】

    任意门:http://hihocoder.com/problemset/problem/1828 Saving Tang Monk II 时间限制:1000ms 单点时限:1000ms 内存限制:25 ...

  6. 【洛谷P1108】低价购买

    低价购买 题目链接 n<=5000 n^2的算法是可以接受的 第一个数字显然是求最长下降子序列,可以n^2或nlognDP 要求方案数,可以在n^2算法中做一些修改,DP求方案数 dp[i]表示 ...

  7. video object detection

    先说一下,我觉得近两年最好的工作吧.其他的,我就不介绍了,因为我懂得少. 微软的jifeng dai的工作. Deep Feature Flow   github: https://github.co ...

  8. 8.Element-ui日期组件上传到后台日期少一天解决办法

    <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="转出日期& ...

  9. 小白袍 -- Chapter 1.1 避不开的编解码

    1.1  避不开的编解码 能阅读本文的想开都是从事计算机开发工作的,那么弱弱的问自己一下,有没有受到过编码的纠缠呢?有没有动过心思,如果没有编码该多好? 1.1.1  这个翻译你得捏着鼻子用 要想说明 ...

  10. linux ccenteros 部署 redis

    step one :  yum install redis    -- 安装redis数据库 step two:安装完成之后开启redis 服务 service redis start   syste ...