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

2024-05-05 19:12

本文主要是介绍蓝桥杯练习系统(算法训练)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

这篇关于蓝桥杯练习系统(算法训练)ALGO-946 Q神的足球赛的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/962458

相关文章

C#实现系统信息监控与获取功能

《C#实现系统信息监控与获取功能》在C#开发的众多应用场景中,获取系统信息以及监控用户操作有着广泛的用途,比如在系统性能优化工具中,需要实时读取CPU、GPU资源信息,本文将详细介绍如何使用C#来实现... 目录前言一、C# 监控键盘1. 原理与实现思路2. 代码实现二、读取 CPU、GPU 资源信息1.

在C#中获取端口号与系统信息的高效实践

《在C#中获取端口号与系统信息的高效实践》在现代软件开发中,尤其是系统管理、运维、监控和性能优化等场景中,了解计算机硬件和网络的状态至关重要,C#作为一种广泛应用的编程语言,提供了丰富的API来帮助开... 目录引言1. 获取端口号信息1.1 获取活动的 TCP 和 UDP 连接说明:应用场景:2. 获取硬

JAVA系统中Spring Boot应用程序的配置文件application.yml使用详解

《JAVA系统中SpringBoot应用程序的配置文件application.yml使用详解》:本文主要介绍JAVA系统中SpringBoot应用程序的配置文件application.yml的... 目录文件路径文件内容解释1. Server 配置2. Spring 配置3. Logging 配置4. Ma

2.1/5.1和7.1声道系统有什么区别? 音频声道的专业知识科普

《2.1/5.1和7.1声道系统有什么区别?音频声道的专业知识科普》当设置环绕声系统时,会遇到2.1、5.1、7.1、7.1.2、9.1等数字,当一遍又一遍地看到它们时,可能想知道它们是什... 想要把智能电视自带的音响升级成专业级的家庭影院系统吗?那么你将面临一个重要的选择——使用 2.1、5.1 还是

高效管理你的Linux系统: Debian操作系统常用命令指南

《高效管理你的Linux系统:Debian操作系统常用命令指南》在Debian操作系统中,了解和掌握常用命令对于提高工作效率和系统管理至关重要,本文将详细介绍Debian的常用命令,帮助读者更好地使... Debian是一个流行的linux发行版,它以其稳定性、强大的软件包管理和丰富的社区资源而闻名。在使用

Ubuntu系统怎么安装Warp? 新一代AI 终端神器安装使用方法

《Ubuntu系统怎么安装Warp?新一代AI终端神器安装使用方法》Warp是一款使用Rust开发的现代化AI终端工具,该怎么再Ubuntu系统中安装使用呢?下面我们就来看看详细教程... Warp Terminal 是一款使用 Rust 开发的现代化「AI 终端」工具。最初它只支持 MACOS,但在 20

windows系统下shutdown重启关机命令超详细教程

《windows系统下shutdown重启关机命令超详细教程》shutdown命令是一个强大的工具,允许你通过命令行快速完成关机、重启或注销操作,本文将为你详细解析shutdown命令的使用方法,并提... 目录一、shutdown 命令简介二、shutdown 命令的基本用法三、远程关机与重启四、实际应用

Python中的随机森林算法与实战

《Python中的随机森林算法与实战》本文详细介绍了随机森林算法,包括其原理、实现步骤、分类和回归案例,并讨论了其优点和缺点,通过面向对象编程实现了一个简单的随机森林模型,并应用于鸢尾花分类和波士顿房... 目录1、随机森林算法概述2、随机森林的原理3、实现步骤4、分类案例:使用随机森林预测鸢尾花品种4.1

Debian如何查看系统版本? 7种轻松查看Debian版本信息的实用方法

《Debian如何查看系统版本?7种轻松查看Debian版本信息的实用方法》Debian是一个广泛使用的Linux发行版,用户有时需要查看其版本信息以进行系统管理、故障排除或兼容性检查,在Debia... 作为最受欢迎的 linux 发行版之一,Debian 的版本信息在日常使用和系统维护中起着至关重要的作

什么是cron? Linux系统下Cron定时任务使用指南

《什么是cron?Linux系统下Cron定时任务使用指南》在日常的Linux系统管理和维护中,定时执行任务是非常常见的需求,你可能需要每天执行备份任务、清理系统日志或运行特定的脚本,而不想每天... 在管理 linux 服务器的过程中,总有一些任务需要我们定期或重复执行。就比如备份任务,通常会选在服务器资