uva 101 The Blocks Problem (模拟)

uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟 挺水的模拟题,刚开始题目看错了,poj竟然过了。。。无奈。uva果断wa了 搞清题目意思后改了一下,过了uva。 题目要求模拟木块移动: 有n(0 move a onto b  在将a搬到b上之前,先把a和b上的积木放回原來的位置 move a over b在将a搬到b所在的那堆积木上前,先把a上的积木放回原來的位罝 pile a onto b 将包括a本身和上方的积木一起放到b上,在 阅读详情

                                   uva 101  The Blocks Problem


Background 

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 

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 n blocks on the table (numbered from 0 to n-1) with block b i adjacent to block b i+1 for all $0 \leq i < n-1$ as shown in the diagram below:
 
\begin{figure}\centering\setlength{\unitlength}{0.0125in} %\begin{picture}(2......raisebox{0pt}[0pt][0pt]{$\bullet\bullet \bullet$ }}}\end{picture}\end{figure}
Figure: Initial Blocks World

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

  • move a onto b

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

  • move a over b

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

  • pile a onto b

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

  • pile a over b

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

  • quit

    terminates manipulations in the block world.

Any command in which a = b or in which a and b 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.

The Input 

The input begins with an integer n on a line by itself representing the number of blocks in the block world. You may assume that 0 < 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.

The Output 

The output should consist of the final state of the blocks world. Each original block position numbered i ( $0 \leq 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., n lines of output where n is the integer on the first line of input).

Sample 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

Sample Output 

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


题目大意:比较繁琐的一题。有四种情况:

1.move a onto b:将a和b上的方块都清空,将a移到b上。

2.move a over b:将a上的方块清空,将a移到b上(移到b所在方块组的最上方)

3.pile a onto b:将b上方方块清空,将a以及a上方所有方块按原顺序移到b上。

4.pile a over b:将a以及a上方所有方块按原有顺序移到b方块所在方块组最上方。

PS:当a等于b,或两方块在同一方块组,视为非法,不作任何操作。                                                                  

解题思路:按照思路模拟,需要细心。


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int block[30][30], n;
int findx(int m) {
	for (int i = 0; i < n; i++) { 
		for (int j = 0; j < n; j++) {
			if (block[i][j] == m) {
				return i;
			}
		}
	}
	return 0;
}
void find(int m, int &a, int &b) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (block[i][j] == 0) break;
			if (block[i][j] == m) {
				a = i;
				b = j;
				return;
			}
		}
	}	
}
void Return(int m, int &x, int &y) {
	int temp;
	find(m, x, y);
	for (int i = y + 1; block[x][i] != 0; i++) {
		temp = block[x][i];
		block[x][i] = 0;
		block[temp - 1][0] = temp;
	}
}
void mo(int a, int b) {
	int x1, y1, x2, y2;
	if (findx(a) == findx(b)) return;
	Return(a, x1, y1);
	Return(b, x2, y2);
	block[x2][y2 + 1] = a;
	block[x1][y1] = 0;
}
void mv(int a, int b) {
	int x1, y1, x2, y2, i;
	if (findx(a) == findx(b)) return;
	Return(a, x1, y1);
	find(b, x2, y2);
	for (i = y2 + 1; block[x2][i] != 0; i++);
	block[x2][i] = a;
	block[x1][y1] = 0;
}
void po(int a, int b) {
	int x1, y1, x2, y2;
	if (findx(a) == findx(b)) return;
	Return(b, x2, y2);
	find(a, x1, y1);
	for (int i = y1; block[x1][i] != 0; i++) {
		block[x2][++y2] = block[x1][i];
		block[x1][i] = 0;
	}
}
void pv(int a, int b) {
	int x1, y1, x2, y2, i;
	if (findx(a) == findx(b)) return;
	find(a, x1, y1);
	find(b, x2, y2);
	for (i = y2 + 1; block[x2][i] != 0; i++);
	for (int j = y1; block[x1][j] != 0; j++) {
		block[x2][i++] = block[x1][j];
		block[x1][j] = 0;
	}
}
int main() {
	scanf("%d\n", &n);   
	memset(block, 0, sizeof(block));	
	for (int i = 0; i < n; i++) {
		block[i][0] = i + 1;
	}
	int a, b;
	char ch[10], order[10];
	while (scanf("%s", ch) == 1, ch[0] != 'q') {
		scanf("%d %s %d", &a, order, &b);
		if (a == b) continue;
		a++; b++;
		if (strcmp(ch, "move") == 0) {
			if (strcmp(order, "onto") == 0) {
				mo(a, b);					
			}
			else {
				mv(a, b);
			}
		}
		else {
			if (strcmp(order, "onto") == 0) {
				po(a, b);
			}
			else {
				pv(a, b);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d:", i);
		for (int j = 0; block[i][j] != 0; j++) {
			printf(" %d", block[i][j] - 1);
		}
		printf("\n");
	}

	return 0;
}




FreeRTOS面试题汇总 如果一个低优先级的任务持有一个信号量,高优先级的任务想要用这个信号量,造成的死锁怎么解决。12.FreeRTOS的多任务之间如何去进行通信的,什么方法,它实现原理是什么。任务间数据传输一共有三种形式,用的最多的是消息队列,其次是全局变量和信号量。简历上写了了解RTOS,问了rtos的问题,用过哪些函数。讲解FreeRtos原理,调度机制,底层原理,代码调用。FreeRTOS,你的三个任务控制,请问你是怎么实现的。freertos中EventBits_t是干啥的?freertos使任务切换的方式有哪些? 阅读详情

相关推荐

使用运放构建电压跟随器

运放,是运算放大器的简称 运算放大器是用模拟电子器件(如晶体管,场效应管,二极管等)构成的模拟集成电路,其特点是有很高的放大倍数和抗干扰能力,因此可以被设计成各种用途的派生电路,如电压比较器、窗口电路、波形发生电路等等,其中也有电压跟随器。 电压跟随器是一种具有100%电压负反馈的放大器电路,其特点是输出电压的幅度和极性都与输入电压相同,所以叫跟随器。典型线路如图所示: 运放跟随器有输入阻抗高,而输出阻抗低的特性,一般来说,输入阻抗可以达到几兆欧姆,而输出阻抗低,通常只有几欧姆,甚至更低。 在电

Code for Coffee 5万+

最新博客地址转移https://bravoing.github.io/

最新博客地址转移:https://github.com/bravoing 欢迎大家收藏

FixedStar 的博客 6万+

深入解析Android14应用安装权限:从声明到授予的完整适配指南

本文深入解析Android14应用安装权限的适配方法,重点介绍了从权限声明到授予的完整流程。与Android13相比,Android14在权限管理机制上进行了重要调整,特别是通过AppOpsManager实现权限的对象化封装。文章详细讲解了权限声明的基础配置、Framework层适配方案、运行时权限授予方法以及常见问题排查指南,帮助开发者高效完成Android14权限适配。

o9p0q1的博客 699

H - A-B Game贪心找规律

Fat brother and Maze are playing a kind of special (hentai) game by two integers A and B. First Fat brother write an integer A on a white paper and then Maze start to change this integer. Every time M...

weixin_43960370的博客 7172

adb 通信协议分析以及实现 (三) (Adb 网络通信部分解析)

这篇文章说下adb 和adb 服务进程之间通信的socket 协议。  adb 服务进程启动之后,会监视本地的5037 端口,使用的是TCP 协议,所以adb 发送的命令其实就是往本地的5037 端口发送数据,做过网络编程的都知道,本机可以用127.0.0.1 ip地址。 有了ip 地址和端口号socket 通信就没问题 1)  命令发送方式      

inforecovvery的博客 2872

Vben Admin权限管理全解析:从动态菜单到按钮级控制(附代码示例)

本文全面解析Vben Admin框架的权限管理系统,从动态菜单生成到按钮级细粒度控制,提供完整的实现方案和代码示例。深入探讨基于角色-权限模型的架构设计,分享前后端协作的最佳实践,帮助开发者快速构建安全高效的企业级后台系统。

weixin_30919429的博客 489

基于jQuery的弹窗小插件

jQuery,弹窗小插件,基于jQuery的弹窗小插件

old brother stable 6万+

Unity插件NodeCanvas之行为树的详细教程

NodeCanvas 是一个用于 Unity 的可视化脚本工具,主要用于游戏开发中的行为树、状态机和流程图的设计。它通过节点编辑器的方式,让开发者可以更直观地创建和管理游戏逻辑,减少了传统编码的复杂性。今天我们就来详细介绍一下NodeCanvas插件。

TxNet 1974

https://www.testingcircus.com/tell-me-about-yourself-6-sample-answers-software-testers/

https://www.testingcircus.com/tell-me-about-yourself-6-sample-answers-software-testers/   Tell Me About Yourself is a very common software testing interview question. It is very important that one s...

weixin_33975951的博客 5502

addBumpConnectTargetConstraint 命令详解

本文介绍了Cadence Innovus中用于倒装芯片设计的addBumpConnectTargetConstraint命令的核心功能和使用方法。该命令主要用于为凸点(Bump)添加连接目标约束,通过绑定实例、引脚/网络和端口号等属性,实现凸点与电源/信号网络的精准映射。文章详细解析了命令语法结构、参数说明及使用场景,包括必选参数(指定凸点方式)、分支选择(实例连接或电源连接类型)以及互斥参数(引脚名与网络名)等重要注意事项,并提供了典型应用示例。该命令特别适用于倒装芯片设计中凸点与PG网络、IO实例的连接

u013620135的博客 397

西南科技大学模拟电子技术实验二(二极管特性测试及其应用电路)预习报告

3、用二极管正向虚拟IV仪测出数据,并记录数据于虚表3和虚表4。1、按照指导书multisim仿真软件上画出三种模型电路图,1、按照指导书multisim仿真软件上画出三种模型电路图,1、按照指导书multisim仿真软件上画出三种模型电路图,表6 二极管三种模型参数测试表(电源电压=1.2V)2、用万用表测出数据,并记录数据于虚表1和虚表2。2、用万用表测出数据,并记录数据于虚表5和虚表6。表5 二极管三种模型参数测试表(电源电压=12V)二极管三种模型参数测试表(电源电压=12V)

Welcome To My6n Blog 4092

【免费下载】 推荐一款跨平台的E-Hentai阅读神器:JHenTai

**项目介绍** 在漫游数字世界的时候,如果你是E-Hentai的爱好者,那么JHenTai绝对值得你拥有。这是一款专为Android、iOS、Windows、macOS和Linux打造的多平台E-Hentai阅读应用,让你随时随地享受轻小说和漫画的乐趣。虽然目前仍处于开发阶段,但其功能完善,用户体验良好,且不断更新迭代,潜力无限。 **项目技术分析** JHenTai采用先进的Flutte

gitblog_00036的博客 9067

YOLOv13改进目录一览 | 涉及卷积层、轻量化、注意力、损失函数、Backbone、SPPF、Neck、检测头等全方位改进

1️⃣ 已更新种不同的改进方案,专栏内的每篇文章皆,均可顺利运行。2️⃣ 订阅专栏即可进群获取以及从的各种答疑内容。3️⃣ 全新的YOLOv13改进专栏,,只为更好的满足论文发表的要求。专栏内容,专栏实时评分,全网最高,质量保证。🎫。。

Limiiiing的博客 9236

UVA101 HDU1612 POJ1208 The Blocks Problem【模拟】

问题链接:UVA101 HDU1612 POJ1208 The Blocks Problem。 问题简述:参见上述链接。 问题分析:这是一个模拟题,程序过程都是套路。 程序说明: 程序中用到了STL的容器类vector。 开始的时候,编写的程序在UVA和POJ中都AC,可是在HDU中是“Presentation Error”。问题出在输出格式上,针对HDU另...

weixin_34198762的博客 97

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Eigen库开发指南:从矩阵运算到性能优化的C++线性代数实战技法

在C++数值计算、机器人、图形学及SLAM等工程领域,线性代数库是底层支撑,而Eigen凭借模板元编程与惰性求值设计,成为公认的高性能选择。基于模板表达式,Eigen在编译期完成优化,实现接近手写代码的执行效率,同时保留接近数学表达的API风格。理解其固定尺寸与动态矩阵的取舍、混叠问题的规避、对齐规则、分解选型策略,是提升代码质量与运行效率的关键。本文聚焦矩阵定义、线性方程组求解、LLT与QR分解等高频操作,结合可复用代码,梳理从基础运算到编译优化的完整路径,帮助开发者避免常见陷阱,在实际项目中充分发挥Ei

weixin_33928137的博客 377

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

UVa 101 The Blocks Problem [模拟]

Description模拟Algorithm模拟 学习Vector用HintHDU 也有这题 用这个代码会 PE UVa 能ACCode#include <iostream> #include <vector> using namespace std; const int maxn = 25 + 9; int n; vector<int> p[maxn]; struct V { int p,

more time 238

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

uva 101 The Blocks Problem 模拟

题意:给定n个箱子,编号为0~n-1。初始时,编号为0的箱子处于0,1处于1,,以此类推。可以进行五种操作。 move a onto b:将a与b上的箱子放回原位。然后将a放到b的上方 move a over b:将a上的箱子放回原位,b上方不动。然后将a堆积在b的上方。 pile a onto b:将b上方所有的箱子放回原位,然后将a以及a上方所有的箱子放到b的上方。 pile a ov

chen_minghui的博客 291

【UVA - 101】The Blocks Problem(vector+模拟)

The Blocks Problem Descriptions:(英语就不说了,直接上翻译吧) 初始时从左到右有n个木块,编号为0~n-1,要求实现下列四种操作: move a onto b: 把a和b上方的木块全部放回初始的位置,然后把a放到b上面 move a over b: 把a上方的木块全部放回初始的位置,然后把a放在b所在木块堆的最上方 pile a onto b: 把b上...

weixin_30293135的博客 213

The Blocks Problem UVA 101 模拟

#include #include using namespace std; int n, num1, num2; char op1[5], op2[5]; vector v[25]; void get(int num, int &x, int &y) { for (int i=0; i<n; i++) for (unsigned int j=0; j<v[i].siz

亂丟程式碼的天空 353

从热传导案例出发:聊聊COMSOL中边界条件设置的常见误区与物理意义

本文以热传导案例为基础,深入探讨COMSOL中边界条件设置的常见误区与物理意义。通过分析狄利克雷、诺伊曼及对流/辐射边界条件的适用场景,帮助用户理解如何正确选择和应用边界条件,避免工程仿真中的常见错误,提升模拟结果的可靠性。

weixin_30932215的博客 317

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】【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

洛谷 UVA101 The Blocks Problem【模拟/链表】

输入格式 输出格式 题意翻译 初始时从左到右有 nnn 个木块,编号为 0…n−10 \ldots n-10…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 的上面。

memcpy0的博客 831
上一篇: hdu 5167 Fibonacci(DFS)
下一篇: uva 10012 How Big Is It?(枚举)
SPZn_up
博客等级 码龄12年 25粉丝 318原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值