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 ...
随机推荐
- ftp的20 21端口和主动被动模式
ftp只支持tcp连接,不支持udp连接. ftp使用两个端口: 21(控制端口, 命令端口) , 20(数据端口) 21端口: 用来控制用户验证, 连接的建立和关闭:open/close/bye ...
- thinkphp 3.23 第三方登录sdk集成包
本集成包在官方包上扩展了支付宝登录和微信,支持最新的3.23版本 config /* URL配置 */ 'URL_CASE_INSENSITIVE' => true, //默认fa ...
- java笔记--反射进阶之总结与详解
一.反射进阶之动态设置类的私有域 "封装"是Java的三大特性之一,为了能更好保证其封装性,我们往往需要将域设置成私有的, 然后通过提供相对应的set和get方法来操作这个域.但是 ...
- springmvc 定时器
CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 1 秒 是 0-59 , - * ...
- 基于贪心算法的几类区间覆盖问题 nyoj 12喷水装置(二) nyoj 14会场安排问题
1)区间完全覆盖问题 问题描述:给定一个长度为m的区间,再给出n条线段的起点和终点(注意这里是闭区间),求最少使用多少条线段可以将整个区间完全覆盖 样例: 区间长度8,可选的覆盖线段[2,6],[1, ...
- PHP 冒泡原理
header('Content-Type: text/html; charset=utf-8'); // 简单冒泡算法 $a = array(5,43,3,2,1); function mp($a){ ...
- load url from future 解释
利用url 标签之后,不管urlpatterns里的某个地址叫法怎么改变,Templates里的地址都不用修改了.在模版中调用url标签的时候,需要:{% load url from future % ...
- js 函数声明方式以及javascript的历史
1.function xx(){} 2.匿名方式 window.onload=function(){dslfjdslfkjdslf}; 3.动态方式 var demo=new Function ...
- 在eclipse中配置一个简单的spring入门项目
spring是一个很优秀的基于Java的轻量级开源框架,为了解决企业级应用的复杂性而创建的,spring不仅可用于服务器端开发,从简单性.可测试性和松耦合性的角度,任何java应用程序都可以利用这个思 ...
- block引发的陷阱
block在项目的开发中使用时非常频繁的,苹果官方也极力推荐使用block.其实,究其本质,block就是指向结构体的指针(可利用运行时机制查看底层生成的c代码).然而在使用block时会存在很多陷阱 ...