Codeforces Round #613 (Div. 2)A. Mezo Playing Zoma
A. Mezo Playing Zoma
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x=0x=0. Mezo starts sending nn commands to Zoma. There are two possible commands:
- 'L' (Left) sets the position x:=x−1x:=x−1;
- 'R' (Right) sets the position x:=x+1x:=x+1.
Unfortunately, Mezo's controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position xx 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 00;
- "LRLR" — Zoma recieves no commands, doesn't move at all and ends up at position 00 as well;
- "LRLR" — Zoma moves to the left, then to the left again and ends up in position −2−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 nn (1≤n≤105)(1≤n≤105) — the number of commands Mezo sends.
The second line contains a string ss of nn commands, each either 'L' (Left) or 'R' (Right).
Output
Print one integer — the number of different positions Zoma may end up at.
Example
input
Copy
4
LRLR
output
Copy
5
Note
In the example, Zoma may end up anywhere between −2−2 and 22.
题意:两种操作,一种是L另一种是R,分别代表减一加一,,起始值为0,问给定一个指令序列值的变化区间长度是多少。
送分题啦,算一下减的最多的,加的最多的,两个相加还有0这个点就是答案~
#include<bits/stdc++.h>
#define ll long long
#define rg register ll
using namespace std;
ll a,b,n;
string s;
int main()
{
cin>>n>>s;
for(rg i=0;s[i];i++)
{
s[i]=='L'?a++:b++;
}
cout<<a+b+1<<endl;
while(1)getchar();
return 0;
}
- CentOS设置Mono环境变量
- 分布式监控系统Zabbix-3.0.3-完整安装记录(2)-添加mysql监控
- 从APM角度上看:NoSQL和关系数据库并无不同
- 事故记录-过多进程致使CPU卡死
- Flash/Flex学习笔记(54):迷你滚动条ScrollBar
- linux下正向代理/反向代理/透明代理使用说明
- 万达网科年底集体裁员?公司回应仅是业务调整
- 两个四字母域名均以五位数被交易
- Flash/Flex学习笔记(15):FMS 3.5之远程共享对象(Remote Shared Object)
- Android Fragment完全解析
- Centos下堡垒机Jumpserver V3.0环境部署完整记录(2)-配置篇
- Flash/Flex学习笔记(53):利用FMS快速创建一个文本聊天室
- 28家银行用户体验调研报告:洞见银行业的“进化论”
- 性能计数器数据收集服务
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Windows10子系统(WSL)修改安装目录
- 二、JSON数据格式
- 一、Ajax的基本用法
- 图解HTTP读书笔记
- Flutter性能调优、复杂业务保证Flutter的高性能高流畅
- requests项目实战--抓取百度热搜
- [代码片段]谷歌的一个不错的CSS样式,不得不说大厂的前端设计师美感就是好。
- 罗马数字转整数
- 找出两个文件中相同的单词(java实现)
- Apache日志变量详解
- 三、jQuery中的Ajax
- SAP ABAP ADBC和Java JDBC的使用比较
- 自己开发的一个SAP CRM订单统计工具
- SAP ABAP和Java跨域请求问题的解决方案
- 使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率