A. Robot Sequence
2 seconds
256 megabytes
standard input
standard output
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices.
The first line of the input contains a single positive integer, n (1 ≤ n ≤ 200) — the number of commands.
The next line contains n characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code.
Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square.
6
URLLDR
2
4
DLUU
0
7
RLRLRLR
12
In the first case, the entire source code works, as well as the "RL" substring in the second and third characters.
Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.
#include<bits/stdc++.h>
using namespace std;
int ud[202];
int rl[202];
int main()
{
int n;
char a; scanf("%d",&n);getchar();
for(int i=0;i<n;i++)
{
scanf("%c",&a);
if(a=='U') ud[i]=1;
else if(a=='D') ud[i]=-1;
else if(a=='R') rl[i]=1;
else rl[i]=-1; }
int ans=0;
int cntud=0;
int cntrl=0;
for(int i=0;i<n;i++)
{
cntud=ud[i];
cntrl=rl[i];
for(int j=i+1;j<n;j++)
{ cntud+=ud[j];
cntrl+=rl[j];
if(cntud==0&&cntrl==0) ans++;
}
}
printf("%d\n",ans);
return 0;
}
A. Robot Sequence的更多相关文章
- Codeforces 626A Robot Sequence
A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence 暴力
A. Robot Sequence 题目连接: http://www.codeforces.com/contest/626/problem/A Description Calvin the robot ...
- Codeforces 626 A. Robot Sequence (8VC Venture Cup 2016-Elimination Round)
A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 前端自动化测试工具doh学习总结(二)
一.robot简介 robot是dojo框架中用来进行前端自动化测试的工具,doh主要目的在于单元测试,而robot可以用来模仿用户操作来测试UI.总所周知,Selenium也是一款比较流行的前端自动 ...
- 8VC Venture Cup 2016 - Elimination Round
在家补补题 模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...
- Codeforces-8VC Venture Cup 2016-Elimination Round-626A.暴力 626B.水题 626C.二分
A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #389 Div.2 C. Santa Claus and Robot
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- CSUFT 1002 Robot Navigation
1002: Robot Navigation Time Limit: 1 Sec Memory Limit: 128 MB Submit: 4 Solved: 2 Descript ...
随机推荐
- 微信公众平台回复过了怎么不能再次回复?亲们要注意查看"公众平台回复用户消息时限变更通知"的公告啊
有网友一直在问“微信公众平台回复过了怎么不能再次回复?”,其实这个是微信公众平台订阅号设置的一个时间限制,一般都会提示:由于该用户48小时未与你互动,你不能再主动发消息给他.直到用户下次主动发消息给你 ...
- Mysql性能监控
show processlist; show global variables like 'max_allowed_packet'; // QPS计算(每秒查询数)show global status ...
- linux shell 流程控制
导读 和Java.PHP等语言不一样,linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case).下面我将通过例子介绍下,各个语句使 ...
- NGUI 图集生成 图片Sprite 有撕裂边的问题
修改 Dimensions 的 X 和 Y值进行调整. 在生成图集时 选择Padding 设置1以上 应该不会出现这个问题.
- chm文件打开空白无内容的解决办法
今天下载了个chm文件,但是打开空白,也没显示什么内容,经过一番研究之后终于可以正常显示了,下面把解决办法分享出来供大家参考下,谢谢. 工具/原料 windows7系统 chm文件 方法/步骤 ...
- Smarty s02
保留变量 方便使用php 不用assign {$smarty} get {$smarty.get.page} session {$smarty.session.user.name} server c ...
- (转)SQL SERVER的锁机制(二)——概述(锁的兼容性与可以锁定的资源)
二.完整的锁兼容性矩阵(见下图) 对上图的是代码说明:见下图. 三.下表列出了数据库引擎可以锁定的资源. 名称 资源 缩写 编码 呈现锁定时,描述该资源的方式 说明 数据行 RID RID 9 文件编 ...
- 现在, Delphi 的多线程已经非常易用了!
先看一个非多线程的例子, 代码执行时不能进行其它操作(譬如拖动窗体): {自定义方法: 在窗体上绘制...} procedure MyMethod; var i: Integer; begin ...
- codeforces 486C. Palindrome Transformation 解题报告
题目链接:http://codeforces.com/problemset/problem/486/C 题目意思:给出一个含有 n 个小写字母的字符串 s 和指针初始化的位置(指向s的某个字符).可以 ...
- Extjs中给同一个GridPanel中的事件添加参数的方法
Extjs中给同一个GridPanel中的事件添加参数的方法: this.isUse = new Ext.Action({ text:'启用', scope ...