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;
}




本地部署 Anything LLM+Ollama+DeepSeek R1 大模型并实现外部访问 DeepSeek 一经发布就引起社会的广泛的关注,因为 DeepSeek 的价格低廉,性能卓越,提供了多种使用方式,满足不同用户的需求和场景。本文将详细的介绍如何在本地 Windows 上安装部署 Anything LLM + Ollama 来实现用户和 DeepSeek-r1 对话的功能以及利用路由侠内网穿透实现外网访问。 阅读详情

相关推荐

英飞凌ADS开发环境搭建全流程:从安装到第一个程序烧录

本文详细介绍了英飞凌ADS开发环境搭建的全流程,包括环境准备、ADS安装与配置、MemTools烧录技巧等关键步骤。针对嵌入式开发者,特别提供了从安装到第一个程序烧录的实战指南,涵盖常见问题解决方案和优化建议,帮助开发者快速上手英飞凌AURIX系列微控制器的开发工作。

qsc901234的博客 296

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

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

FixedStar 的博客 6万+

CoilDesigner4-8-20204-1123-R1-20201201104713.zip

CoilDesigner翅片换热器模拟软件。CoilDesigner最新版通过丰富多样的板片尺寸,波纹角度和流道布置可以灵活设计,可以通过板片数量的增减调整来满足不同热负荷的要求。

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的博客 7163

基于jQuery的弹窗小插件

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

old brother stable 6万+

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的博客 5075

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

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

gitblog_00036的博客 8965

UVA101 HDU1612 POJ1208 The Blocks Problem模拟

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

weixin_34198762的博客 94

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 237

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的博客 288

UVA - 101The 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的博客 207

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

亂丟程式碼的天空 352

【免费下载】 JHenTai 漫画阅读器开源项目教程

JHenTai 是一个跨平台的漫画应用程序,专为e-hentai和exhentai爱好者设计。该项目采用Flutter框架开发,支持Android、iOS、Windows、MacOS及Linux等操作系统。虽然仍处于开发阶段,但已具有基本功能,包括下载、搜索、设置等功能。用户可以通过提交问题或功能请求来参与项目的发展。 ## 2. 项目快速启动 ### 安装依赖 确保你已经安装了以下软件: -

gitblog_00702的博客 7699

JHenTai:全平台E-Hentai漫画阅读器,打造极致二次元体验

还在为找不到合适的E-Hentai阅读工具而烦恼吗?JHenTai这款基于Flutter开发的全平台漫画阅读应用,将彻底改变你的二次元内容消费方式。无论你使用的是手机、平板还是电脑,JHenTai都能提供流畅统一的阅读体验,让你随时随地沉浸在精彩的漫画世界中。 ## 🎯 从零开始:JHenTai快速部署指南 ### 环境准备与项目获取 首先确保你的系统已安装Flutter开发环境,然后通过

gitblog_01189的博客 2386

如何快速上手JHenTai漫画阅读器?终极指南来了!

还在为寻找一款优秀的跨平台漫画阅读器而烦恼吗?JHenTai漫画阅读器正是你需要的解决方案!这款基于Flutter开发的应用完美支持Android、iOS、Windows、MacOS和Linux五大平台,让你在手机、平板、电脑之间无缝切换阅读体验。 ## 🚀 快速入门:5分钟开启漫画之旅 想要立即体验JHenTai漫画阅读器的强大功能?只需简单几步: 1. **获取应用**:访问项目仓库

gitblog_00276的博客 1219

JHenTai:跨平台E-Hentai漫画阅读神器完全指南 [特殊字符]

想要在任何设备上畅享E-Hentai和ExHentai的漫画内容吗?JHenTai作为一款基于Flutter开发的跨平台漫画阅读器,为你提供了完美的解决方案。无论你是Windows、Mac、Linux用户,还是Android、iOS移动用户,这款开源工具都能让你轻松访问和管理海量漫画资源。 ## 🔍 什么是JHenTai? JHenTai是一款专门为E-Hentai和ExHentai设计的跨

gitblog_00741的博客 1324

JHenTai:全平台E-Hentai阅读器深度体验与使用指南

想要在任何设备上都能畅享E-Hentai的漫画世界吗?JHenTai作为一款基于Flutter开发的跨平台应用,彻底打破了设备壁垒,让你在Android、iOS、Windows、macOS和Linux系统间无缝切换,享受一致的阅读体验。 ## 核心优势深度解析:为什么JHenTai成为首选 ### 多设备适配,智能界面切换 JHenTai最大的亮点在于其出色的设备适配能力。无论是手机的小屏触

gitblog_01169的博客 1739

JHenTai:跨平台E-Hentai阅读神器

JHenTai是一款专为E-Hentai和ExHentai设计的跨平台Flutter应用,支持Android、iOS、Windows、macOS和Linux五大操作系统。无论是手持设备还是桌面电脑,都能为用户提供流畅的漫画阅读体验。 ## 多平台全面支持 JHenTai采用Flutter框架开发,具备一次编写多端运行的强大能力。应用完美适配移动设备和桌面环境,提供三种布局模式: - 手机模式:

gitblog_00610的博客 1973
上一篇: hdu 5167 Fibonacci(DFS)
下一篇: uva 10012 How Big Is It?(枚举)
SPZn_up
博客等级 码龄12年 25粉丝 318原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值