参考: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. ABAP宏的调试

    我们都知道高级语言宏一般是无法调试的.但是ABAP的宏例外. 比如我写了下面一段宏,名为insert_table. 执行这段代码,调试器会在第23行停下来. ABAP调试器里有个工具可以用于宏的调试, ...

  2. MHA 一主一从搭建

    安装基本环境介绍 一主一从     MHA manager & slave  node2 192.168.56.27 Master机器 node1 192.168.56.26 VIP   19 ...

  3. GPU使用

    GPU .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1p ...

  4. softmax实现cifar10分类

    将cifar10改成单一通道后,套用前面的softmax分类,分类率40%左右,想哭... .caret, .dropup > .btn > .caret { border-top-col ...

  5. [18/11/22] 将点分十进制的IP地址化成二进制输出

    #include <stdio.h> void binary(int d){ ,j,n,b[]={}; ){ n=d%; d=d/; b[i++]=n; //不停的除2,余数保存在b[8] ...

  6. table自适应

    当table大于屏幕时,table可以左右滑动 //给table的父元素设置样式 .edit_table{ width:100%; overflow: auto; }

  7. MVC学习一:MVC简单流程

    MVC学习一:MVC初次接触 1.MVC简单流程 1.1.服务器接收客户端请求后,解析URL(根据 路由表里配置的URL来分析 类名(控制器名)和方法名)根据请求的类名,创建对应的控制器类对象,并调用 ...

  8. 理解Storm可靠性消息

    看过一些别人写的, 感觉有些东西没太说清楚,个人主要以源代码跟踪,参考个人理解讲述,有错误请指正. 1基本名词 1.1 Tuple: 消息传递的基本单位.很多文章中介绍都是这么说的, 个人觉得应该更详 ...

  9. CONVERT函数----SQL

    CONVERT函数是把时间转换成新类型的通用格式,这样方便查询 CONVERT(type,expression,style) type: 例如:varchar(10)  数据库字符串的类型,大小可以自 ...

  10. linux c做服务端使用多线程接收图片并且将图片写入数据库

    #include<sys/socket.h> #include<sys/types.h> #include<sys/stat.h>//包含文件的全部结构,属性 #i ...