B -- POJ 1208 The Blocks Problem
参考: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的更多相关文章
- POJ 1208 The Blocks Problem
The Blocks Problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5397 Accepted: 231 ...
- POJ 1208 The Blocks Problem --vector
http://poj.org/problem?id=1208 晚点仔细看 https://blog.csdn.net/yxz8102/article/details/53098575 #include ...
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...
- PKU 1208 The Blocks Problem(模拟+list应用)
题目大意:原题链接 关键是正确理解题目意思 首先:介绍一下list容器的一些操作:参考链接 list<int> c1; c1.unique(); 去重. c1.r ...
- The Blocks Problem(vector)
题目链接:http://poj.org/problem?id=1208 The Blocks Problem Time Limit: 1000MS Memory Limit: 10000K Tot ...
- UVa 101 The Blocks Problem Vector基本操作
UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that inst ...
- UVa 101 - The Blocks Problem(积木问题,指令操作)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...
- POJ 1208 模拟
2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...
随机推荐
- C#并行库(TaskParallelLibrary)用法 z
1. Task.Factory.StartNew(() => DoSomeWork());是异步的 下面的代码会先输出ddd,因为Task.Factory.Startnew不阻塞: var ta ...
- laravel5.4学习笔记
1.安装laravel可以直接用composer安装,然后用laravel new xxx来新建项目 服务器上安装了composer(php包管理工具)以后, composer global requ ...
- 微信小程序国际化
微信小程序国际化 现状 小程序国际化官方没有支持,也没有现成的插件. 网上有人做了国际化的尝试.但是只能替换静态文本,就是简单的键值匹配. vue-i18n 由于是基于html 和 vue, 不同于w ...
- 319. Bulb Switcher (Math, Pattern)
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...
- python接口测试-项目实践(三)数据的处理示例
三 数据处理 枚举值的转换.如接口返回1-5,需转成对应的中文. typecap = findinfo_from_api(result, 'TypeCap') dictcap = {': '微盘'} ...
- 网络体系结构的概念 - 网络协议TCP - 红黑联盟
https://i.cnblogs.com/EditPosts.aspx?opt=1 网络体系结构的概念 计算机网络就是一组通过一定形式连接起来的计算机系统,它需要四个要素的支持,即通信线路和通信设 ...
- POJ 3321 DFS序
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30636 Accepted: 9162 Descr ...
- HDU 6070 线段树
题意:求AC率,x/y 的最小值,x是区间数字的种类数,y是区间的长度. 分析: 二分答案比率.ans, 动态插入结点,一些区间的size会发生变化,是那些前面暂时没有新的结点的区间 size + 1 ...
- unbuntu循环登录
http://www.myexception.cn/operating-system/1707766.html
- Maven 搭建spring boot多模块项目
Maven 搭建spring boot多模块项目 备注:所有项目都在idea中创建 1.idea创建maven项目 1-1: 删除src,target目录,只保留pom.xml 1-2: 根目录pom ...