CF1285A. Mezo Playing Zoma

2024-04-16 02:08
文章标签 playing cf1285a mezo zoma

本文主要是介绍CF1285A. Mezo Playing Zoma,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Today, Mezo is playing a game. Zoma, a character in that game, is initially at position 𝑥=0. Mezo starts sending 𝑛 commands to Zoma. There are two possible commands:

‘L’ (Left) sets the position 𝑥:=𝑥−1;
‘R’ (Right) sets the position 𝑥:=𝑥+1.
Unfortunately, Mezo’s controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position 𝑥 doesn’t change and Mezo simply proceeds to the next command.

For example, if Mezo sends commands “LRLR”, then here are some possible outcomes (underlined commands are sent successfully):

“LRLR” — Zoma moves to the left, to the right, to the left again and to the right for the final time, ending up at position 0;
“LRLR” — Zoma recieves no commands, doesn’t move at all and ends up at position 0 as well;
“LRLR” — Zoma moves to the left, then to the left again and ends up in position −2.
Mezo doesn’t know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.

Input
The first line contains 𝑛 (1≤𝑛≤105) — the number of commands Mezo sends.

The second line contains a string 𝑠 of 𝑛 commands, each either ‘L’ (Left) or ‘R’ (Right).

Output
Print one integer — the number of different positions Zoma may end up at.

Example
inputCopy
4
LRLR
outputCopy
5
Note
In the example, Zoma may end up anywhere between −2 and 2.

题意:
起点(0,0)
L代表向左走一格,R代表右走一格
有些操作可能失效
问能走过多少个格子。

#include <cstdio>
#include <cstring>
#include <algorithm>using namespace std;char s[100005];
int main()
{int n;scanf("%d",&n);scanf("%s",s);int L = 0,R = 0;for(int i = 1;i <= n;i++){if(s[i] == 'L')L++;else R++;}printf("%d\n",L + R + 1);return 0;
}

这篇关于CF1285A. Mezo Playing Zoma的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

CodeForces 378A Playing with Dice(水题)

题目链接: CodeForces 378A Playing with Dice 题目大意:两个人猜数1~6,给出a和b,然后随机丢一个色子,问说接近a的可能,相等的可能,以及接近b的可能。 解题思路:完完全全的签到题。 #include <stdio.h>#include <stdlib.h>#include <math.h>int main() {int

深入浅出软件开发----(三)Playing Poker Game

通过无限制头脑风暴、角色扮演、实地观察等需求获取手段得到了一系列定义良好的User Story之后,我们就要根据需求来评估整个开发过程需要的工作量了。        在这里我们用到了一个有意思的方法----Playing Poker Game,游戏是这样进行的 :   将一个定义良好、描述清晰的User Story放到桌子中间参与估算的每一个成员给出一个完成User Story

Leetcode 3021. Alice and Bob Playing Flower Game

Leetcode 3021. Alice and Bob Playing Flower Game 1. 解题思路2. 代码实现 题目链接:3021. Alice and Bob Playing Flower Game 1. 解题思路 这一题真心很蠢,事实上就是只要 x + y x+y x+y为奇数Alick就能赢,因此只要看在给定的 m , n m,n m,n的情况下能组合出多少和为奇数的p

Playing with Numbers(Kattis - playingwithnumbers)(预处理瞎搞)

题目链接:https://vjudge.net/problem/Kattis-playingwithnumbers 题目描述:给定n组a b的值,每组表示一个数值2^a*3^b,共进行n次操作,第i次操作可以进行i-1次gcd操作和 n - i次lcm操作,求每次操作后所得最大值及最小值对应的ab分别是多少。每次选取任意两个数进行gcd操作时,只将结果放回这些数字中,lcm也是。 思路:当至少

camel-ai的role_playing代码解读

这段代码定义了一个名为RolePlaying的类,用于两个角色之间的角色扮演。 该类接受以下参数: assistant_role_name (str): 助手扮演的角色名称。user_role_name (str): 用户扮演的角色名称。critic_role_name (str): 评论家扮演的角色名称。带有”:obj:"human"“的角色名称会将评论家设置为Human代理,否则将创建一个

UESTC 1661 Playing With Stones 博弈打表

You and your friend are playing a game in which you and your friend take turns removing stones from piles. Initially there are  N N piles with  a1,a2,a3,…,aN a1,a2,a3,…,aN number of stones. On each

A. Playing with Paper

这是Codeforces Round #296 (Div. 2)的A题,题意就是: 小明有一张长为a,宽为b的纸,每当要折纸鹤时,就从纸上剪下一个正方形,然后,剩下的纸还可以剪出正方形,要是剩下的纸刚好是正方形的话,就直接拿这个正方形去做最后一个纸鹤,求总共可以折多少个纸鹤。小明是个节约资源的好孩子。 _______________ input  2 1 output  2 __________

JoyRL文献笔记-1-Playing Atari with Deep Reinforcement Learning

Mnih V, Kavukcuoglu K, Silver D, et al. Playing atari with deep reinforcement learning[J]. arXiv preprint arXiv:1312.5602, 2013.   本文的贡献:是深度强化学习算法DQN的开山之作,是第一篇将深度学习DL感知能力与强化学习RL序贯决策能力相结合的论文。本文提出了第一个通

Learning to play snake at 1 million FPS Playing snake with advantage actor-critic

在这篇博文中,我将引导您完成我最近的项目,该项目结合了我发现的两件令人着迷的东西 - 电脑游戏和机器学习。 很长一段时间以来,我一直想深入了解强化学习,我认为没有比做自己的项目更好的方法了。 为此,我在PyTorch中实现了经典的手机游戏“Snake”,并训练了强化学习算法来进行游戏。 这篇文章分为三个部分。 Snake游戏的大规模并行矢量化实现Advantage Actor-Critic(A2

Learning to play snake at 1 million FPS Playing snake with advantage actor-critic

在这篇博文中,我将引导您完成我最近的项目,该项目结合了我发现的两件令人着迷的东西 - 电脑游戏和机器学习。 很长一段时间以来,我一直想深入了解强化学习,我认为没有比做自己的项目更好的方法了。 为此,我在PyTorch中实现了经典的手机游戏“Snake”,并训练了强化学习算法来进行游戏。 这篇文章分为三个部分。 Snake游戏的大规模并行矢量化实现Advantage Actor-Critic(A2