B. Move and Turn(数论 思维

本文探讨了一个机器人在二维平面上移动的问题。机器人每次可以向北、南、东、西四个方向移动一米,并在每一步之后必须左转或右转90度。问题要求计算在n步后机器人可以到达的不同位置数量。程序通过判断步数的奇偶性来计算结果,对于偶数步,答案是(n/2+1)的平方;对于奇数步,答案是(n/2+1)的平方加上(n/2+2)的平方。这个题目涉及到了动态规划和路径计数的概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

添加链接描述
如果是偶数,可以上下和左右分别走n/2+1
如果是奇数,左右上下分别为n/2+1或者n/2+2 两种情况要累加
A robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly 1 meter in one of the four cardinal directions: north, south, west, and east. For the first step the robot can choose any of the four directions, but then at the end of every second it has to turn 90 degrees left or right with respect to the direction it just moved in. For example, if the robot has just moved north or south, the next step it takes has to be either west or east, and vice versa.

The robot makes exactly n steps from its starting position according to the rules above. How many different points can the robot arrive to at the end? The final orientation of the robot can be ignored.

Input
The only line contains a single integer n (1≤n≤1000) — the number of steps the robot makes.

Output
Print a single integer — the number of different possible locations after exactly n steps.

#include<bits/stdc++.h>
using namespace std;
int main(){
	
	int n;
	cin>>n;
	int p=n/2;
	if(n%2==0)cout<<(p+1)*(p+1);
	else cout<<(p+1)*(p+2)*2;
	
	
	return 0;
}
在这里插入代码片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值