参考: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. nginx-rtmp加入权限验证的简单方法

    nginx-rtmp-module默认不限制推流权限.播放权限.如果想加入权限验证,有很多种方法. 方法一:修改源码如: 如何给 nginx rtmp 服务加入鉴权机制 http://blog.csd ...

  2. Unix 和 Linux 安装 Perl

    Unix/Linux 系统上 Perl 安装步骤如下: 通过浏览器打开 http://www.perl.org/get.html. 下载适用于 Unix/Linux 的源码包. 下载 perl-5.x ...

  3. Bootstrap Table的使用小结

    1.Jquery中的一些东西学习一下子,补充完善一下,毕竟有些时候没有使用到 这个方式很有用,在使用bootstrap table的时候,选择当前已经选择的节点的事件中的ID的值 当前rows中有很多 ...

  4. 【转】总结oninput、onchange与onpropertychange事件的用法和区别

    经本人测试在chrome下的从历史记录中选取值的时候也户触发input事件 前端页面开发的很多情况下都需要实时监听文本框输入,比如腾讯微博编写140字的微博时输入框hu9i动态显示还可以输入的字数.过 ...

  5. 广义线性模型(GLM, Generalized Linear Model)

    引言:通过高斯模型得到最小二乘法(线性回归),即:      通过伯努利模型得到逻辑回归,即:      这些模型都可以通过广义线性模型得到.广义线性模型是把自变量的线性预测函数当作因变量的估计值.在 ...

  6. Code First 一

    Code-First和我们的数据库优先方式是相反的,数据库优先是通过数据库映射出相应的类和上下文,Code-First测试通过创建的类和上下文得到相应的数据库. Code-First主要用于领域驱动设 ...

  7. c语言描述的直接插入排序法

    #include<stdio.h> #include<stdlib.h> #define SIZE 6 typedef int Type; //直接插入排序法 void Ins ...

  8. 用c#语言编写银行利率

    sing System;using System.Collections.Generic;using System.Linq;using System.Text; namespace ConsoleA ...

  9. 使用Dapper处理多个结果集和多重映射的教程

    在本文中,我们将介绍如何使用DAPPER从单个数据库调用中读取数据库中的多个结果集.我们将看看我们可能希望这样做的场景,以及如何使用它的Query和QueryMultiple方法更简洁地实现这一点. ...

  10. JS中对象继承方式

    JS对象继承方式 摘自<JavaScript的对象继承方式,有几种写法>,作者:peakedness 链接:https://my.oschina.net/u/3970421/blog/28 ...