蓝桥杯练习系统(算法训练)ALGO-946 Q神的足球赛

资源限制

内存限制:256.0MB   C/C++时间限制:1.0s   Java时间限制:3.0s   Python时间限制:5.0s

问题描述

  足球赛上,只见Q神如闪电般的速度带球时而左,时而右,时而前,时而后,时而上,时而下……等等,有什么奇怪的东西混进去了?假设Q神力量可以突破地心引力,他在一个三维空间里面可以沿着直角坐标系的坐标轴方向前进。告诉你他的每一次转的方向以及前进的距离,请你回答他最后在哪个位置,面朝那一个方向。假设他一开始在(0,0,0),面朝x轴的正方向。

输入格式

  多组输入数据。
  每组第一行是一个整数n。接下来n行每行一个字符表示方向,接着一个整数表示前进距离。其中,f(forward)表示继续前进,方向不变;b(back)表示向后转;l(left)表示向左转;r(right)表示像右转;u(up)表示向上;d(表示向下)。如图示。

输出格式

  对于每一组数据,输出Q神的坐标和他的朝向。其中:左手系的x正方向、y正方向、z正方向分别位0、1、2,对应的负方向分别为3、4、5.

样例输入

6
l 10
r 11
u 12
d 13
f 14
b 15

样例输出

23 -10 12 3

数据规模和约定

  数据组数不超过10组,n《=200 ,每次移动距离不超过100

#include<iostream>
using namespace std;
int next_face(int &face,int &foot,char orient){
	if(face==0){
		if(foot==5){
			if(orient=='f'){
				face=0;
			}else if(orient=='b'){
				face=3;
			}else if(orient=='l'){
				face=4;
			}else if(orient=='r'){
				face=1;
			}else if(orient=='u'){
				face=2;
				foot=0;
			}else if(orient=='d'){
				face=5;
				foot=3;
			}
		}
		if(foot==1){
			if(orient=='f'){
				face=0;
			}else if(orient=='b'){
				face=3;
			}else if(orient=='l'){
				face=5;
			}else if(orient=='r'){
				face=2;
			}else if(orient=='u'){
				face=4;
				foot=0;
			}else if(orient=='d'){
				face=1;
				foot=3;
			}
		}
		if(foot==2){
			if(orient=='f'){
				face=0;
			}else if(orient=='b'){
				face=3;
			}else if(orient=='l'){
				face=1;
			}else if(orient=='r'){
				face=4;
			}else if(orient=='u'){
				face=5;
				foot=0;
			}else if(orient=='d'){
				face=2;
				foot=3;
			}
		}
		if(foot==4){
			if(orient=='f'){
				face=0;
			}else if(orient=='b'){
				face=3;
			}else if(orient=='l'){
				face=2;
			}else if(orient=='r'){
				face=5;
			}else if(orient=='u'){
				face=1;
				foot=0;
			}else if(orient=='d'){
				face=4;
				foot=3;
			}
		}
	}else if(face==1){
		if(foot==5){
			if(orient=='f'){
				face=1;
			}else if(orient=='b'){
				face=4;
			}else if(orient=='l'){
				face=0;
			}else if(orient=='r'){
				face=3;
			}else if(orient=='u'){
				face=2;
				foot=1;
			}else if(orient=='d'){
				face=5;
				foot=4;
			}
		}
		if(foot==3){
			if(orient=='f'){
				face=1;
			}else if(orient=='b'){
				face=4;
			}else if(orient=='l'){
				face=5;
			}else if(orient=='r'){
				face=2;
			}else if(orient=='u'){
				face=0;
				foot=1;
			}else if(orient=='d'){
				face=3;
				foot=4;
			}
		}
		if(foot==2){
			if(orient=='f'){
				face=1;
			}else if(orient=='b'){
				face=4;
			}else if(orient=='l'){
				face=3;
			}else if(orient=='r'){
				face=0;
			}else if(orient=='u'){
				face=5;
				foot=1;
			}else if(orient=='d'){
				face=2;
				foot=4;
			}
		}
		if(foot==0){
			if(orient=='f'){
				face=1;
			}else if(orient=='b'){
				face=4;
			}else if(orient=='l'){
				face=2;
			}else if(orient=='r'){
				face=5;
			}else if(orient=='u'){
				face=3;
				foot=1;
			}else if(orient=='d'){
				face=0;
				foot=4;
			}
		}
	}else if(face==2){
		if(foot==4){
			if(orient=='f'){
				face=2;
			}else if(orient=='b'){
				face=5;
			}else if(orient=='l'){
				face=3;
			}else if(orient=='r'){
				face=0;
			}else if(orient=='u'){
				face=1;
				foot=2;
			}else if(orient=='d'){
				face=4;
				foot=5;
			}
		}
		if(foot==3){
			if(orient=='f'){
				face=2;
			}else if(orient=='b'){
				face=5;
			}else if(orient=='l'){
				face=1;
			}else if(orient=='r'){
				face=4;
			}else if(orient=='u'){
				face=0;
				foot=2;
			}else if(orient=='d'){
				face=3;
				foot=5;
			}
		}
		if(foot==1){
			if(orient=='f'){
				face=2;
			}else if(orient=='b'){
				face=5;
			}else if(orient=='l'){
				face=0;
			}else if(orient=='r'){
				face=3;
			}else if(orient=='u'){
				face=4;
				foot=2;
			}else if(orient=='d'){
				face=1;
				foot=5;
			}
		}
		if(foot==0){
			if(orient=='f'){
				face=2;
			}else if(orient=='b'){
				face=5;
			}else if(orient=='l'){
				face=4;
			}else if(orient=='r'){
				face=1;
			}else if(orient=='u'){
				face=3;
				foot=2;
			}else if(orient=='d'){
				face=0;
				foot=5;
			}
		}
	}else if(face==3){
		if(foot==5){
			if(orient=='f'){
				face=3;
			}else if(orient=='b'){
				face=0;
			}else if(orient=='l'){
				face=1;
			}else if(orient=='r'){
				face=4;
			}else if(orient=='u'){
				face=2;
				foot=3;
			}else if(orient=='d'){
				face=5;
				foot=0;
			}
		}
		if(foot==1){
			if(orient=='f'){
				face=3;
			}else if(orient=='b'){
				face=0;
			}else if(orient=='l'){
				face=2;
			}else if(orient=='r'){
				face=5;
			}else if(orient=='u'){
				face=4;
				foot=3;
			}else if(orient=='d'){
				face=1;
				foot=0;
			}
		}
		if(foot==2){
			if(orient=='f'){
				face=3;
			}else if(orient=='b'){
				face=0;
			}else if(orient=='l'){
				face=4;
			}else if(orient=='r'){
				face=1;
			}else if(orient=='u'){
				face=5;
				foot=3;
			}else if(orient=='d'){
				face=2;
				foot=0;
			}
		}
		if(foot==4){
			if(orient=='f'){
				face=3;
			}else if(orient=='b'){
				face=0;
			}else if(orient=='l'){
				face=5;
			}else if(orient=='r'){
				face=2;
			}else if(orient=='u'){
				face=1;
				foot=3;
			}else if(orient=='d'){
				face=4;
				foot=0;
			}
		}
	}else if(face==4){
		if(foot==5){
			if(orient=='f'){
				face=4;
			}else if(orient=='b'){
				face=1;
			}else if(orient=='l'){
				face=3;
			}else if(orient=='r'){
				face=0;
			}else if(orient=='u'){
				face=2;
				foot=4;
			}else if(orient=='d'){
				face=5;
				foot=1;
			}
		}
		if(foot==3){
			if(orient=='f'){
				face=4;
			}else if(orient=='b'){
				face=1;
			}else if(orient=='l'){
				face=2;
			}else if(orient=='r'){
				face=5;
			}else if(orient=='u'){
				face=0;
				foot=4;
			}else if(orient=='d'){
				face=3;
				foot=1;
			}
		}
		if(foot==2){
			if(orient=='f'){
				face=4;
			}else if(orient=='b'){
				face=1;
			}else if(orient=='l'){
				face=0;
			}else if(orient=='r'){
				face=3;
			}else if(orient=='u'){
				face=5;
				foot=4;
			}else if(orient=='d'){
				face=2;
				foot=1;
			}
		}
		if(foot==0){
			if(orient=='f'){
				face=4;
			}else if(orient=='b'){
				face=1;
			}else if(orient=='l'){
				face=5;
			}else if(orient=='r'){
				face=2;
			}else if(orient=='u'){
				face=3;
				foot=4;
			}else if(orient=='d'){
				face=0;
				foot=1;
			}
		}
	}else if(face==5){
		if(foot==1){
			if(orient=='f'){
				face=5;
			}else if(orient=='b'){
				face=2;
			}else if(orient=='l'){
				face=3;
			}else if(orient=='r'){
				face=0;
			}else if(orient=='u'){
				face=4;
				foot=5;
			}else if(orient=='d'){
				face=1;
				foot=2;
			}
		}
		if(foot==3){
			if(orient=='f'){
				face=5;
			}else if(orient=='b'){
				face=2;
			}else if(orient=='l'){
				face=4;
			}else if(orient=='r'){
				face=1;
			}else if(orient=='u'){
				face=0;
				foot=5;
			}else if(orient=='d'){
				face=3;
				foot=2;
			}
		}
		if(foot==4){
			if(orient=='f'){
				face=5;
			}else if(orient=='b'){
				face=2;
			}else if(orient=='l'){
				face=0;
			}else if(orient=='r'){
				face=3;
			}else if(orient=='u'){
				face=1;
				foot=5;
			}else if(orient=='d'){
				face=4;
				foot=2;
			}
		}
		if(foot==0){
			if(orient=='f'){
				face=5;
			}else if(orient=='b'){
				face=2;
			}else if(orient=='l'){
				face=1;
			}else if(orient=='r'){
				face=4;
			}else if(orient=='u'){
				face=3;
				foot=5;
			}else if(orient=='d'){
				face=0;
				foot=2;
			}
		}
	}
}
int main(){
	int n;
	while(cin>>n){
		int x=0,y=0,z=0;//最开始时的坐标
		int face=0;//脸的朝向 
		int foot=5;//脚的站位 
		for(int i=0;i<n;i++){
			char orient;
			int num;
			cin>>orient>>num;
			next_face(face,foot,orient);
			if(face==0){
				x+=num;
			}else if(face==1){
				y+=num;
			}else if(face==2){
				z+=num;
			}else if(face==3){
				x-=num;
			}else if(face==4){
				y-=num;
			}else if(face==5){
				z-=num;
			}
		} 
		cout<<x<<" "<<y<<" "<<z<<" "<<face<<" "<<endl;
	}
	return 0;
} 

思路:需要知道Q神的脸的朝向、脚的站位(头指向脚的方向)才能确定Q神的位置。已知脸的朝向,可能有4个站位。

例如:初始位置:脸的朝向为0,脚的站位为5

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/605954.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

带你入门React

目录 前言一&#xff0c;基本配置1.1 环境搭建1.2 页面初始化渲染二&#xff0c;基础学习2.1 结构与样式开发2.2 数据展示2.3 行内样式2.4 条件渲染2.5 列表渲染2.6 点击事件 三&#xff0c;页面更新3.1 组件数据3.2 组件数据共享 总结 前言 笔者之前的工作经验都局限于Vue&am…

pandas快速使用

DataFrame介绍 Dateframe结构和列表类似&#xff0c;区别是对于DataFrame的每一列和每一行均有一个标签。例如以下数据&#xff0c; 上述数据中&#xff0c;日期作为每行的标签。a、b、c、d、e分别是每列的标签 生成连续日期数据 使用方法date_range()&#xff0c;该方法有两…

Lazada商品详情API接口:深度解析与应用

前言 在当今电子商务的繁荣时代&#xff0c;对于电商平台来说&#xff0c;提供一套高效、稳定的API接口是非常重要的。Lazada&#xff0c;作为东南亚领先的电商平台之一&#xff0c;其API接口体系为卖家、开发者以及第三方服务提供了丰富的功能和数据支持。其中&#xff0c;商品…

邦注科技 模具保护器 CCD电子眼 专业工业视觉检测设备

模具保护器是一种用于保护模具的设备&#xff0c;可以在塑料压铸和冲床等加工过程中起到保护模具的作用。以下是关于模具保护器在保护塑料压铸和冲床模具方面的应用&#xff1a; 塑料压铸模具保护器&#xff1a; 防止碰撞&#xff1a;在塑料压铸过程中&#xff0c;模具可能会…

初识C++ · 内存管理

目录 1 C/C的内存分布 2 C语言的内存管理 3 C的内存管理 4 operator new 和 operator delete 5 定位new 1 C/C的内存分布 语言不同&#xff0c;内存分布是相同的&#xff0c;对于局部变量都是放在栈上&#xff0c;全局变量都是放在静态区&#xff08;数据段&#xff09;&…

jvm重要参数可视化和线上问题排查

jvm重要参数可视化和线上问题排查 目标jvm参数分类(了解)运行时数据区相关的&#xff08;jdk1.8&#xff09;处理 OOM 相关的垃圾回收器相关的GC 日志记录相关的意义,默认值,调优原则&#xff08;重要&#xff0c; 待拆分&#xff09; 排查 OOM 流程 和 常见原因参考文章 目标 …

基于C语言中的类型转换,C++标准创造出了更加可视化的类型转换

目录 前言 一、 C语言中的类型转换 二、为什么C需要四种类型转换 三、C中新增的四种强制类型转换操作符以及它们的应用场景 1.static_cast 2.reinterpret_cast 3.const_cast 4.dynamic_cast 前言 在C语言中&#xff0c;如果赋值运算符左右两侧的类型不同&#xff0c;或者…

短视频矩阵系统贴牌---saas源头开发

一、短视频矩阵运营注意事项&#xff1a; 如&#xff1a;房产行业 短视频矩阵运营是一个系统化的项目&#xff0c;涉及多个平台和账号的管理&#xff0c;以及内容的创作、发布和优化等多个方面。 以下是短视频矩阵运营的注意事项文档的概要以及结果运营数据 一周持续运营量 二…

uni-app 多列picker切换列显示对应内容

html部分&#xff1a; <view class"uni-list"><view class"uni-list-cell"><view class"uni-list-cell-left">选择用户</view><view class"uni-list-cell-db"><picker mode"multiSelector"…

【JavaWeb】网上蛋糕商城后台-类目管理,退出

概念 本文讲解和实现类目管理和管理员的退出功能。 类目列表信息 点击类目管理&#xff0c;向服务器发送请求/admin/type_list 在servlet包中创建AdminTypeListServlet类&#xff0c;获得所有商品分类 package servlet;import model.Type; import service.TypeService;impo…

网站localhost和127.0.0.1可以访问,本地ip不可访问解决方案

部署了一个网站, 使用localhost和127.0.0.1加端口号可以访问, 但是使用本机的ip地址加端口号却不行. 原因可能有多种. 可能的原因: 1 首先要确认是否localhost对应的端口是通的(直接网址访问), 以及你无法访问的那个本机ip是否正确(使用ping测试)&#xff1b; 2 检查本机的防火…

堆的基本操作(c语言实现)

1.堆的基本操作 1.1定义堆 typedef int HPDataType;//堆中存储数据的类型typedef struct Heap {HPDataType* a;//用于存储数据的数组int size;//记录堆中已有元素个数int capacity;//记录堆的容量 }HP;1.2初始化堆 然后我们需要一个初始化函数&#xff0c;对刚创建的堆进行初…

软件测试开发之 职业发展必备 能力模型解析

为什么要了解能力模型 王阳明曾在《传习录》中提到过一个思想&#xff1a;以终为始。所谓“以终为始”&#xff0c;意味着在行动的开始阶段就要考虑到最终的目标和结果&#xff0c;以此来指导自己的行动和选择。那么如果我们想在自己的行业内获取好的职业发展&#xff0c;第一…

Meta更低的训练成本取得更好的性能: 多token预测(Multi-Token Prediction)

Meta提出了一种透过多token预测(Multi-token Prediction)来训练更好、更快的大型语言模型的方法。这篇论文的重点如下: 训练语言模型同时预测多个未来的token,可以提高样本效率(sample efficiency)。 在推论阶段,使用多token预测可以达到最高3倍的加速。 论文的主要贡献包括: …

2024年Delphi自学培训网络资源

概述 Delphi 是一种基于 Object Pascal 的面向对象编程语言。最初&#xff0c;Delphi 是作为构建 Windows 应用程序的工具而创建的&#xff0c;并于 1995 年发布。从那时起&#xff0c;这些技术向前迈出了一大步&#xff0c;Delphi也不例外。尽管第一个用 Delphi 编写的应用程…

Windows 10 中使用 Montreal-Forced-Aligner (MFA) 实现音频和文本强制对齐

文章目录 一、实现目标二、安装 Montreal-Forced-Aligner1、使用 Anaconda 虚拟环境2、修改默认下载路径3、安装 montreal-forced-aligner 及相关第三方包4、验证是否安装成功 三、下载声学模型和发音词典1、命令行方式下载2、手动方式下载 四、强制对齐1、准备音频及对应文本2…

docker学习笔记(三)搭建NFS服务实验

目录 什么是NFS 简单架构​编辑 一.搭建nfs服务器 二.新建共享目录和网页文件 三.设置共享目录 四&#xff1a;创建使用nfs共享目录的卷 五&#xff1a;创建容器使用nfs-web-1卷 六&#xff1a;测试访问 七&#xff1a;是否同步测试 什么是NFS NFS 服务器&#xff1a;ne…

人工智能将改变科研?从胰腺癌早筛到新药研发

去年底英国《自然》杂志刊文预测的2024年十大科学进展中&#xff0c;人工智能的进步和ChatGPT人工智能占据前两位。那么&#xff0c;人工智能对于科学而言&#xff0c;它的哪些成果将带来有益的发展&#xff1f;今天我们请知名科普作者张田勘来聊聊这个话题。 &#xff08;1&am…

万兆以太网MAC设计(13)主机与FPGA之间进行PING

文章目录 前言&#xff1a;一、ICMP校验和计算二、上板效果1、终端命令行1、wireshark捕捉 前言&#xff1a; 在上板尝试进行PING操作的时候&#xff0c;发现一直是请求超时的情况&#xff0c;结果排查发现是首部校验和没有计算的问题。在UDP层&#xff0c;我们不进行校验和是…

ReentrantReadWriteLock源码分析

ReentrantReadWriteLock是基于AQS实现的读写锁&#xff0c;读锁与读锁不互斥、读锁与写锁互斥、写锁与写锁互斥。 类的继承关系 AQS提供了共享和排它两种模式&#xff0c;acquire/release、acquireShared/releaseShared 是AQS里面的两对模板方法。写锁是排它模式基于acquire/…
最新文章