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

news2024/9/20 12:42:19

资源限制

内存限制: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.coloradmin.cn/o/1666829.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

HDFS HA 修改nameservice

本例中修改将原来的hdfs-ha 修改为 hdfs-ns 停止HDFS, 防止新的业务操作 等待停止结束 KDE中需要调整的配置项如下图所示 a.搜索栏找到fs.defaultFS&#xff0c;将hdfs://hdfs-ha改为hdfs://hdfs-ns b.搜索栏找到dfs.nameservices&#xff0c;将hdfs-ha改为hdfs-ns c.搜索栏找…

HBuilder报错--openssl-legacy-provider is not allowed in NODE_OPTIONS解决方法

目录 一、问题描述二、解决方法 一、问题描述 HBuilder编译时报错&#xff1a;–openssl-legacy-provider is not allowed in NODE_OPTIONS 二、解决方法 将 windows 环境变量 NODE_OPTIONS 的值设置为空&#xff0c;由&#xff1a; 改为&#xff1a;

并发-判断线程对象是否处于活动状态 - isAlive

t.isAlive() 测试线程t是否处于活动状态&#xff0c;只要线程启动并且没有终止&#xff0c;方法返回值就是truestart()之前&#xff0c;线程不处于活动状态&#xff0c;之后就处于活动状态示例&#xff1a;运行结果&#xff1a;但是事情并没有这么简单&#xff0c;先来看一下以…

【每日刷题】Day37

【每日刷题】Day37 &#x1f955;个人主页&#xff1a;开敲&#x1f349; &#x1f525;所属专栏&#xff1a;每日刷题&#x1f34d; &#x1f33c;文章目录&#x1f33c; 1. 2391. 收集垃圾的最少总时间 - 力扣&#xff08;LeetCode&#xff09; 2. 1614. 括号的最大嵌套深度…

软件库V1.5版本iApp源码V3

软件库V1.5版本iApp源码V3 配置教程在【mian.iyu】的【载入事件】 更新内容&#xff1a; 1、分类对接蓝奏&#xff08;免费&#xff0c;付费&#xff0c;会员&#xff0c;广告&#xff09;&#xff0c;支持蓝奏文件描述设置为简介&#xff08;改动&#xff1a;首页.iyu&#…

【算法】二叉树中的dfs

快乐的流畅&#xff1a;个人主页 个人专栏&#xff1a;《算法神殿》《数据结构世界》《进击的C》 远方有一堆篝火&#xff0c;在为久候之人燃烧&#xff01; 文章目录 引言一、计算布尔二叉树的值二、求根节点到叶节点数字之和三、二叉树剪枝四、验证搜索二叉树五、二叉搜索树中…

该从哪些方面提升系统的吞吐量?

更多大厂面试内容可见 -> http://11come.cn 该从哪些方面提升系统的吞吐量&#xff1f; 我们平时自己做的项目一般没有用户量&#xff0c;都是练手项目&#xff0c;所以并不会在吞吐量上做出很多的优化&#xff0c;但是这样的话&#xff0c;又会导致项目和其他人相比并没有…

mysql设置远程访问权限,允许其他IP访问

文章目录 更改mysql配置文件登录mysql 更改mysql配置文件 查找.ini或者.cnf文件 更改bind-address为0.0.0.0 [mysqld] character-set-serverutf8mb4 bind-address0.0.0.0 default-storage-engineINNODB [mysql] default-character-setutf8mb4 [client] default-character-s…

ppt保存文件奇怪问题

我发现ppt中的形状保存成jpg,png和pdf时&#xff0c;格式不一样 比如 当右键单击时&#xff0c;然后选择另存为图片 png格式 jpg格式 pdf格式 感觉还是很奇怪&#xff0c;就pdf的格式比较靠谱一点

Java---类和对象第一节

目录 1.面向对象初步认识 1.1什么是面向对象 1.2面向对象和面向过程的区别 2.类的定义和使用 2.1简单认识类 2.2类的定义格式 2.3类的实例化 2.4类和对象的说明 3.this关键字 3.1访问本类成员变量 3.2调用构造方法初始化成员变量 3.3this引用的特性 4.对象的构造以…

国内有哪些知名的网络安全厂商?

首先就是360&#xff0c;这个我相信大家并不陌生了吧&#xff0c;你的电脑装过360么&#xff1f; 360在个人终端服务那是妥妥的扛把子&#xff0c;但是在企业服务里虽然有他们的身影却略显不足。 第二个就是深信服&#xff0c;网络安全的老牌大佬&#xff0c;业务覆盖了全球5…

什么是XXE漏洞,日常如何做好web安全,避免漏洞威胁

随着网络技术的不断发展&#xff0c;网站安全问题日益受到人们的关注。当前随着技术发展&#xff0c;网站存在一些常见的可能被攻击者利用的漏洞&#xff0c;而在众多网站安全漏洞中&#xff0c;XXE&#xff08;XML External Entity&#xff09;漏洞是一个不容忽视的问题。今天…

linux性能监控之slabtop

slabtop命令是以实时的方式显示内核slab缓冲区的细节信息&#xff0c;是linux自带的命令 [rootk8s-master ~]# slabtop --helpUsage:slabtop [options]Options:-d, --delay <secs> delay updates-o, --once only display once, then exit-s, --sort <char&…

【WEEK11】 【DAY6】员工管理系统第七部分【中文版】

2024.5.11 Saturday 接上文【WEEK11】 【DAY5】员工管理系统第六部分【中文版】 目录 10.8.删除及404处理10.8.1.修改list.html10.8.2.修改EmployeeController.java10.8.3.重启10.8.4. 404页面处理10.8.4.1.把404.html文件移入10.8.4.2.重启并运行 10.8.5.退出登录状态10.8.5.1…

51基于单片机的温室大棚系统设计

设计摘要&#xff1a; 本设计旨在基于51单片机和蓝牙技术&#xff0c;实现一个功能完善的温室大棚系统。该系统具备以下主要功能&#xff1a;首先&#xff0c;通过连接的显示屏能够实时地显示当前的温度和湿度信息&#xff0c;方便用户了解温室内的环境变化。其次&#xff0c;…

Codeforces Round 605 (Div. 3) A~D

本人水平不高&#xff0c;开这个专栏主要是督促自己补题&#xff0c;有些题对目前的我来说还比较难&#xff0c;还补不动&#xff0c;等以后能力上来了再补。。。 原题链接&#xff1a;Dashboard - Codeforces Round 605 (Div. 3) - Codeforces 目录 A. Three Friends B. Sn…

✨✨使用vue3打造一个el-form表单及高德地图的关联组件实例✨

✨1. 实现功能 &#x1f31f;表单内显示省市县以及详细地址 点击省市县输入框时&#xff0c;打开对应地图弹窗&#xff0c;进行位置选择选择位置回显入对应输入框表单内的省市县以及地址输入框同外嵌表单走相同的校验方式触发校验后点击reset实现清除校验与清空数据 &#x1f…

Web开发小知识点(二)

1.关于取余 我在Dart语言里&#xff08;flutter项目&#xff09; int checkNum (10 - 29) % 10; 那么checkNum等于1 但是在Vue项目里 const checkNum (10 - 29) % 10;却等于-9 语言的特性不同&#xff0c;导致结果也不同&#xff0c;如果要想和Dart保持一致&#xff0c;…

Task Office for Mac v9.0激活版:任务管理新境界

还在为繁琐的任务管理而烦恼吗&#xff1f;Task Office for Mac为您带来全新的任务管理体验。简洁明了的界面设计&#xff0c;让您轻松上手&#xff1b;强大的任务管理和项目管理功能&#xff0c;让您轻松掌握任务进度&#xff1b;多用户协作功能&#xff0c;让团队协作更加高效…

自定义实现 Java17+SpringBoot3+OpenAPI+Knife4j Starter

文章目录 前言正文1 创建starter项目1.1 依赖文件1.2 配置信息 2 自定义starer代码开发2.1 配置字段的定义2.2 自动配置类 3 验证starter3.1 测试项目的配置3.2 功能配置 application.yml3.3 测试代码3.3.1 实体类3.3.2 控制器13.3.2 控制器2 4 效果展示4.1 主页4.2 实体类列表…