蓝桥杯练习系统(算法训练)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

相关文章

Linux系统中查询JDK安装目录的几种常用方法

《Linux系统中查询JDK安装目录的几种常用方法》:本文主要介绍Linux系统中查询JDK安装目录的几种常用方法,方法分别是通过update-alternatives、Java命令、环境变量及目... 目录方法 1:通过update-alternatives查询(推荐)方法 2:检查所有已安装的 JDK方

Linux系统之lvcreate命令使用解读

《Linux系统之lvcreate命令使用解读》lvcreate是LVM中创建逻辑卷的核心命令,支持线性、条带化、RAID、镜像、快照、瘦池和缓存池等多种类型,实现灵活存储资源管理,需注意空间分配、R... 目录lvcreate命令详解一、命令概述二、语法格式三、核心功能四、选项详解五、使用示例1. 创建逻

使用Python构建一个高效的日志处理系统

《使用Python构建一个高效的日志处理系统》这篇文章主要为大家详细讲解了如何使用Python开发一个专业的日志分析工具,能够自动化处理、分析和可视化各类日志文件,大幅提升运维效率,需要的可以了解下... 目录环境准备工具功能概述完整代码实现代码深度解析1. 类设计与初始化2. 日志解析核心逻辑3. 文件处

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

Linux系统性能检测命令详解

《Linux系统性能检测命令详解》本文介绍了Linux系统常用的监控命令(如top、vmstat、iostat、htop等)及其参数功能,涵盖进程状态、内存使用、磁盘I/O、系统负载等多维度资源监控,... 目录toppsuptimevmstatIOStatiotopslabtophtopdstatnmon

Java中的雪花算法Snowflake解析与实践技巧

《Java中的雪花算法Snowflake解析与实践技巧》本文解析了雪花算法的原理、Java实现及生产实践,涵盖ID结构、位运算技巧、时钟回拨处理、WorkerId分配等关键点,并探讨了百度UidGen... 目录一、雪花算法核心原理1.1 算法起源1.2 ID结构详解1.3 核心特性二、Java实现解析2.

linux重启命令有哪些? 7个实用的Linux系统重启命令汇总

《linux重启命令有哪些?7个实用的Linux系统重启命令汇总》Linux系统提供了多种重启命令,常用的包括shutdown-r、reboot、init6等,不同命令适用于不同场景,本文将详细... 在管理和维护 linux 服务器时,完成系统更新、故障排查或日常维护后,重启系统往往是必不可少的步骤。本文

Mac系统下卸载JAVA和JDK的步骤

《Mac系统下卸载JAVA和JDK的步骤》JDK是Java语言的软件开发工具包,它提供了开发和运行Java应用程序所需的工具、库和资源,:本文主要介绍Mac系统下卸载JAVA和JDK的相关资料,需... 目录1. 卸载系统自带的 Java 版本检查当前 Java 版本通过命令卸载系统 Java2. 卸载自定

基于Python实现一个简单的题库与在线考试系统

《基于Python实现一个简单的题库与在线考试系统》在当今信息化教育时代,在线学习与考试系统已成为教育技术领域的重要组成部分,本文就来介绍一下如何使用Python和PyQt5框架开发一个名为白泽题库系... 目录概述功能特点界面展示系统架构设计类结构图Excel题库填写格式模板题库题目填写格式表核心数据结构

Linux系统中的firewall-offline-cmd详解(收藏版)

《Linux系统中的firewall-offline-cmd详解(收藏版)》firewall-offline-cmd是firewalld的一个命令行工具,专门设计用于在没有运行firewalld服务的... 目录主要用途基本语法选项1. 状态管理2. 区域管理3. 服务管理4. 端口管理5. ICMP 阻断