The Blocks Problem(stl)

基于 VS Code + CMake + Make + GNU工具链 + OpenOCD 的通用MCU开发环境搭建教程 以CH32V307(RISCV)和STM32F103(Cortex-M3)为例的Vscode+gnu单片机环境搭建。 阅读详情

Description

Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world in which a robot arm performed tasks involving the manipulation of blocks.

In this problem you will model a simple block world under certain rules and constraints. Rather than determine how to achieve a specified state, you will ``program'' a robotic arm to respond to a limited set of commands.

The problem is to parse a series of commands that instruct a robot arm in how to manipulate blocks that lie on a flat table. Initially there are nn blocks on the table (numbered from 0 to n−1n−1) with block bibi adjacent to block bi+1bi+1 for all 0≤i<n−10≤i<n−1 as shown in the diagram below: 

The valid commands for the robot arm that manipulates blocks are:

  • move aa onto bb

where aa and bb are block numbers, puts block aa onto block bb after returning any blocks that are stacked on top of blocks aa and bb to their initial positions.

  • move aa over bb

where aa and bb are block numbers, puts block aa onto the top of the stack containing block bb, after returning any blocks that are stacked on top of block a to their initial positions.

  • pile aa onto bb

where aa and bb are block numbers, moves the pile of blocks consisting of block aa, and any blocks that are stacked above block aa, onto block bb. All blocks on top of block bb are moved to their initial positions prior to the pile taking place. The blocks stacked above block aa retain their order when moved.

  • pile aa over bb

where aa and bb are block numbers, puts the pile of blocks consisting of block aa, and any blocks that are stacked above block aa, onto the top of the stack containing block bb. The blocks stacked above block a retain their original order when moved.

  • quit

terminates manipulations in the block world.

Any command in which a=ba=b or in which aa and bb are in the same stack of blocks is an illegal command. All illegal commands should be ignored and should have no affect on the configuration of blocks.

Input

The input begins with an integer nn on a line by itself representing the number of blocks in the block world. You may assume that 0<n<250<n<25.

The number of blocks is followed by a sequence of block commands, one command per line. Your program should process all commands until the quit command is encountered.

You may assume that all commands will be of the form specified above. There will be no syntactically incorrect commands.

Output

The output should consist of the final state of the blocks world. Each original block position numbered ii ( 0≤i<n0≤i<n, where n is the number of blocks) should appear followed immediately by a colon. If there is at least a block on it, the colon must be followed by one space, followed by a list of blocks that appear stacked in that position with each block number separated from other block numbers by a space. Don't put any trailing spaces on a line.

There should be one line of output for each block position (i.e., nn lines of output where nn is the integer on the first line of input).

Samples

Input 

10
move 9 onto 1
move 8 over 1
move 7 over 1
move 6 over 1
pile 8 over 6
pile 8 over 5
move 2 over 1
move 4 over 9
quit

Output

0: 0
1: 1 9 2 4
2:
3: 3
4:
5: 5 8 7 6
6:
7:
8:
9:

 分析:

读英文题太难受了,没别的办法只能多做题了。

题意:

一开始0~n-1号块上只有自己本身:1上是1,2上是2...

四个操作:

1.把a和b上面的块归位(1回到1号,2回到2号...),再把a放到b上。

2.把a上面的归位,b不用,再把a接到b所在块上。

3.b上面的归位,把a及其上面的块放到b上。

4.直接把a及其上面的块接到b所在块上。

用vector模拟。

#include<bits/stdc++.h>
using namespace std;
vector<int> v[30];
int n;
int find1(int a)//返回在哪一列 
{
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<v[i].size();j++)
		{
			if(v[i][j]==a)return i;
		}
	}
}
int find2(int a)//返回在某一列的哪一个位置 
{
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<v[i].size();j++)
		{
			if(v[i][j]==a)return j;
		}
	}
}
void guiwei(int i,int j)//归位 
{
	int t;
	if(j>=v[i].size()-1)return;
	for(t=j+1;t<v[i].size();t++)
	{
		v[v[i][t]].push_back(v[i][t]);
	}
		v[i].erase(v[i].begin()+j+1,v[i].end());//归位后记得要删除 
	
}
int main()
{
	int i,j;
	cin>>n;
	string s1,s2;
	
	for( i=0;i<n;i++)v[i].push_back(i);
	while(cin>>s1)
	{
		int a,b;
		if(s1=="quit")break;
		cin>>a>>s2>>b;
		if(a==b)continue;//细节1: 同一个数不用管 
		int x1,x2,x3,x4;
		x1=find1(a);x2=find2(a);//查找a b的位置 
		x3=find1(b);x4=find2(b);
		if(x1==x3)continue;//细节2:在同一列不用管 
		if(s1=="move")
		{
			if(s2=="onto")
			{
				guiwei(x1,x2);
				guiwei(x3,x4);
				v[x1].erase(v[x1].begin()+x2);
				v[x3].push_back(a);
			}
			else
			{
				guiwei(x1,x2);
				v[x1].erase(v[x1].begin()+x2);
				v[x3].push_back(a);
			}
		}
		else if(s1=="pile")
		{
			if(s2=="onto")
			{
				guiwei(x3,x4);
				
				for(i=x2;i<v[x1].size();i++)
				v[x3].push_back(v[x1][i]);
			    
			    v[x1].erase(v[x1].begin()+x2,v[x1].end());
			    
			}
			else 
			{
				for(i=x2;i<v[x1].size();i++)
				{
				v[x3].push_back(v[x1][i]);
			    }
			    
			    v[x1].erase(v[x1].begin()+x2,v[x1].end());
			}
		}
	}
	for(i=0;i<n;i++)
	{
		cout<<i<<':';
		if(v[i].size()!=0)
		{
		for(j=0;j<v[i].size();j++)
		{
			cout<<' '<<v[i][j];
		}
	    }
		cout<<'\n';
	}
	
}

第一次发博客,没有大佬们的高超技艺,只想记录一下学习历程,多总结沉淀,希望和大家共进步!

一次搞懂 OData Deep Create:在 ABAP Client Proxy 中优雅完成父子实体的一键插入 摘要: 本文面向熟悉SAP Gateway与OData的ABAP工程师,详解Deep Create的核心概念与实现。Deep Create允许在一次请求中原子化创建主实体及其关联子实体(如Team与Manager),解决多次HTTP请求导致的脏写问题。对比OData v2/v4协议差异后,重点阐述ABAP Client Proxy中通过Data Description Node构造层级数据描述树的方法,包括根/子节点定义、属性对齐及业务数据绑定。提供可复用的ABAP代码骨架,并区分Deep Create与$ 阅读详情

相关推荐

VFIO框架源码分析(一)- 从初始化到设备访问

本文深入剖析了Linux内核中的VFIO(Virtual Function I/O)框架,详细解读了其从初始化到设备访问的全过程。VFIO通过Container->Group->Device的层次化设计,利用IOMMU提供安全隔离,允许用户空间直接访问物理设备。文章基于Linux v5.15版本,重点分析了vfio_init模块入口、Container创建与配置、Group关联以及最终设备访问等关键环节,揭示了VFIO如何通过逐层授权机制构建安全可靠的设备直通模型,为虚拟化技术提供核心支持。

qq_36071928的博客 383

Uva 101:木块问题 The Blocks Problem(详细说明)+(难点)

算法竞赛入门经典 开始接触ACM,老师推荐了紫皮书,但是C++渣渣的我读题都很费劲,搜罗博主文章发现几乎都是 原题+代码 。现尽己所能整理,比较啰(xiang)嗦(xi),希望能对同起步小白有所帮助,嘻嘻。 STL初步:不定长数组:vector 什么是vector? 向量(Vector)是一个封装了动态大小数组的顺序容器(Sequence Container)。跟任意其它类型容器一样,它能够存放各...

weixin_43827530的博客 4296

如何快速获取SAMM、SMIC等主流微表情数据集?完整申请指南(附避坑技巧)

本文提供了获取SAMM、SMIC等主流微表情数据集的完整申请指南,包括申请前的准备工作、分步申请流程、协议谈判技巧以及数据使用与维护策略。特别针对高分辨率动态捕捉和多模态同步数据等热词,帮助研究者高效获取高质量数据集,避免常见陷阱。

weixin_29057163的博客 431

一篇让你快速读懂——木块问题(The Blocks Problem)

题意翻译 初始时从左到右有n个木块,编号为0…n−1,要求实现下列四种操作: move a onto b: 把a和b上方的木块归位,然后把a放到b上面。 move a over b: 把a上方的木块归位,然后把a放在b所在木块堆的最上方。 pile a onto b: 把b上方的木块归位,然后把a及以上的木块坨到b上面。 pile a over b: 把a及以上的木块坨到b的上面。 一组数据的结束标志为quit,如果有非法指令(如a与b

abeijixingdeye的博客 697

模拟IC设计避坑:手把手教你用Cadence仿真恒定跨导轨到轨运放(附完整工艺库文件)

本文详细解析了使用Cadence仿真恒定跨导轨到轨运放的全流程,涵盖电路原理、工艺库配置、尺寸设计及仿真分析。通过1:3电流镜补偿技术实现跨导稳定,提供CSMC 0.25um工艺下的实战案例,帮助工程师规避设计陷阱,提升模拟IC设计效率。

weixin_30952535的博客 505

一文整理深度学习【深度学习linux的docker+pytorch+cuda+nvidia-docker+vscode配置】

docker+pytorch+cuda+nvidia-docker+vscode

LetsonH的博客 1341

木块问题(The Blocks Problem,Uva 101)

原题摘录 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置。现对这些木块进行操作,操作分为四种。 1、move a onto b:把木块a、b上的木块放回各自的原位,再把a放到b上; 2、move a over b:把a上的木块放回各自的原位,再把a发到含b的堆上; 3、pile a onto b:把b上的木块放回各自的原位,再把a连同a上的木块移到b上; 4...

2020 1163

【问题解决】Python 异步 asyncio 卡死、协程不执行、任务泄漏,保姆级排错

本文详细分析了Python异步编程中常见的卡死、协程不执行和任务泄漏问题。文章首先列举了这些问题的典型表现,如程序卡住、死锁、任务未启动等。然后深入剖析了各类问题的根源,包括同步阻塞操作、未正确await、资源未清理等。针对这些问题,文章提供了两套解决方案:一是异步编程最佳实践,包括安全协程执行、带超时的执行、任务清理等实用方法;二是死锁检测和预防机制,通过锁管理和等待图分析来避免死锁。文章还包含可直接使用的代码示例,帮助开发者快速定位和解决异步编程中的常见问题。

博客 451

The Blocks Problem (木块问题) (vector)

题目链接:The Blocks Problem 题意:从左到右有n个木块,编号为0~n-1  ,要求模拟一下四种操作(a,b是木块的编号) **move a onto b:  把a和b上方的木块全部归位,然后把a摞在b上面。 **move a over b:  把a上方的木块全部归位,然后把a放在b所在木块堆的顶部。 **pile a onto b:把b及上面的木块整体摞在b所偶在木块堆的...

yuewenyao的博客 2747

手把手教你学Simulink——基于经典PID控制的电机系统场景实例:BLDC电机PID电流控制策略仿真

*无刷直流电机(Brushless DC Motor, BLDC)**因其高效率、长寿命和低维护成本,在众多领域如家用电器、工业自动化、电动汽车等得到了广泛应用。为了实现对BLDC电机的有效控制,通常采用基于霍尔传感器或反电动势检测的换相技术,并结合电流闭环控制以提高系统的动态响应和稳定性。本教程将带你使用构建一个基于PID控制的BLDC电机电流控制策略仿真模型BLDC电机建模PID控制器设计与应用系统仿真与调试控制效果分析本文介绍了如何使用构建一个。

MHD0815的博客 205

UniApp 覆盖安装后首次进入 APP pages.json 不生效的解决方案

通过以上步骤,解决了缓存问题导致的首次加载异常。此方案的关键在于强制更新文件名,从根本上避免旧缓存的干扰。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 696

The Blocks Problem 栈入栈出

好久没写博客了,今天A了一道题,发一下,一次AC的,不是很绕,有的人可能题,读不懂,这里附上翻译                                                                   The Blocks Problem 内容 : 在早期人工智慧的領域中常常會用到機器人,在這個問題中有一支機器手臂接受指令來搬動積木,而你的任務就是

花月阁 814

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

STL-B The Blocks Problem

Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world in which a r...

a765528534的博客 211

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

UVa 101 The Blocks Problem【STL-vector】

https://vjudge.net/problem/UVA-101 紫书代码 关于vector的一些操作 vector-不定长数组 a.size() 读取大小 a.resize() 改变大小 a.push_back() 向尾部添加一个元素 a.pop_back() 从尾部删除一个元素 a.clear() 清空 a.empty() 测试是否为空 int n; vector<int> p...

之虎者也的博客 182

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【STL基础05】The Blocks Problem

题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;page=show_problem&amp;problem=37题目大意:给出n-1个按标号顺序排列的木块,放在0~n-1个位置,根据以下四条命令进行相应操作move a onto b:把木块a、b上的木块放回原位,再把a放到b上; ...

雄英通信站 505

The Blocks Problem stl vector 模拟

The Blocks Problem stl vector 模拟 试题解析: #include<iostream> #include<vector> #include<string> using namespace std; int n; vector<int> ss[26]; void find(int num,int &loc,int &h) //返回方块num 的堆数和高度 { for(int i=0;i&lt

weixin_45448563的博客 151

UVa101-The Blocks Problem/STL-Vector的使用

取出指令共同点,减少重复代码 利用STL中不定长数组vector vector a;//也可以,这里a是构建了一个不定长一维数组,a[maxn]也可以,构建一个二维数组 a.size() //a的长度 a.push_back(b);//向a的尾部添加元素b,应该是不能加一串只加单个元素 a.resize(h);//将a的第h-1后的元素删掉,in other words, 保留前h个元素

他的博客 400

POJ 1208 The Blocks Problem 栈模拟 练STL

/** * 栈模拟题: 拿来练STL的 * 第一次RE了,因为在move a的时候,a上方的block 只是pop了 但是没有push回原来的栈 * 也就是没有归位,而是单纯的出栈。 * 在判断命令的时候,其实只要分成两类,move 和 pile ,把这两命令视为cmd1 * 后面的 onto 和 over 视为cmd2。 先判断是 move 还是 pile,在判断是onto

xuruoxin的专栏 917

UVA 101 The Blocks Problem STL+模拟

题目:给你n个方块,有四种操作:             1.move a onto b,把a和b上面的方块都放回原来位置,然后把a放到b上面;             2.move a over b,把a上面的放回原处,然后把a放在b所在的方块堆的上面;             3.pile a onto b,把b上面的放回原来位置,然后把a和a上面的方块整体放到b上面;        ...

祈的博客 260

UVa 101 The Blocks Problem 【STL】【vector】【模拟】

题目:点击打开链接 紫书110页 小技巧:输入的四种指令,找到其共同点会使代码简单多 AC代码: #include #include #include #include #include #include using namespace std; const int maxn = 30; int n; vector pile[maxn]; void find_block(i

咸鱼の小窝 386

UVa 101 The Blocks Problem (STL+模拟)

题目传送门 题意(紫书P110): 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置。现对这些木块进行操作,操作分为四种。 1、move a onto b:把木块a、b上的木块放回各自的原位,再把a放到b上; 2、move a over b:把a上的木块放回各自的原位,再把a发到含b的堆上; 3、pile a onto b:把b上的木块放回各自的原位,再把a连...

ytuyzh的博客 223

UVA - 101 The Blocks Problem(STL,模拟)

The Blocks Problem Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Background  Many areas of Computer Science use s

luciozhang的博客 1219

UVa 101 - The Blocks Problem(STL)

The Blocks Problem  Background  Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AIstudy of planning and robot

huatian5的博客 848

UVA101The Blocks Problem(小模拟+STL)

B - The Blocks Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatus Description Download as PDF Background Many areas of Computer Science use simple, abstr

eddddd’ world 1674

UVa 101 - The Blocks Problem STL

题目:给你n个方块,有四种操作: 1.move a onto b,把a和b上面的方块都放回原来位置,然后把a放到b上面; 2.move a over b,把a上面的放回原处,然后把a放在b所在的方块堆的上面; 3.pile a onto b,把b上面的放回原来位置,然后把a和a上面的方块整体放到b上面; ...

weixin_34023863的博客 143

UVA - 00101 The Blocks Problem(STL,vector)

5.2.2不定长数组vector 1.vector就是一个不定长数组。不仅如此,它把一些常用操作”封装“在vector类型内部。例如,若a是一个vector,可以用a.size()读取它的大小,a.resize()改变大小,a.push_back()向尾部添加元素,a.pop_back()删除最后一个元素,a.clear()清空,a.empty测试是否为空。 2.vector是一个模板类,所以...

weixin_30797199的博客 117
下一篇: 2022天梯赛lv2 龙龙送外卖
归去来兮♞
博客等级 码龄5年 6粉丝 19原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值