参考: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. JUnit报错:java.lang.ClassNotFoundException: com.mogodb.test.test

    最近在使用JUnit做单元测试时,发现新写好的测试类运行总是出错,报找不到类异常. Class not found com.mogodb.test.test java.lang.ClassNotFou ...

  2. jQuery 资料

    jQuery 元素选择器 jQuery 使用 CSS 选择器来选取 HTML 元素. $("p") 选取 <p> 元素. $("p.intro") ...

  3. Qt 线程初识别

    Qt有两种多线程的方法,其中一种是继承QThread的run函数,另外一种是把一个继承于QObject的类转移到一个Thread里. 这里我使用的是继承的方法使用线程花一个"复杂" ...

  4. oracle 比较两个用户表结构的区别。

    create table ESPACE_TABLE ( TABLE_NAME ) not null ) create table ESPACE_COLUMN ( TABLE_NAME ) not nu ...

  5. 最简单的docker教程:在docker里运行nginx服务器

    命令行docker search nginx搜索名为nginx的docker image,返回结果的第一个,github上有10293个star,这就是我们想要搜索的结果: 使用命令docker pu ...

  6. python入门16 递归函数 高阶函数

    递归函数:函数内部调用自身.(要注意跳出条件,否则会死循环) 高阶函数:函数的参数包含函数 递归函数 #coding:utf-8 #/usr/bin/python """ ...

  7. 面向对象编程(OOP)、面向组件编程(COP)、面向方面编程(AOP)和面向服务编程(SOP)

    http://blog.csdn.net/hjf19790118/article/details/6919265 1.什么是面向对象编程(Object-Oriented Programming)? 面 ...

  8. 什么是React中的组件

    组件就是页面上的一部分.如图,左边是一个网页.右边是对应的一个组件图.我们可以把一个大的网页拆分成很多小的部分.比如标题部分,对应一个组件,就是标题组件.搜索部分,对应的组件就是搜索组件.而这个搜索组 ...

  9. 可持久化线段树(主席树)快速简洁教程 图文并茂 保证学会。kth number例题

    如果学不会也不要打我. 假设你会线段树 开始! --- 主席树也叫可持久化线段树 顾名思义,它能够保存线段树在每个时刻的版本. 什么叫每个时刻的版本?你可能对一棵普通线段树进行各种修改,这每种样子就是 ...

  10. HDU 1711 Number Sequence 【KMP应用 求成功匹配子串的最小下标】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/O ...