A. Robot Sequence

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output: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.

Input

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.

Output

Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square.

Examples
Input
6
URLLDR
Output
2
Input
4
DLUU
Output
0
Input
7
RLRLRLR
Output
12
Note

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.

题目链接:http://codeforces.com/contest/626/problem/A

题意:在一块方格里,给出一串指令包含U,D,L,R这些字母,分别表示上下左右移动一格。问有多少个子串(包含自身)能使得物体回到出发位置。

分析:模拟一下找子串的个数即可!

解释下样例3:子串为:RL,RLRL,RLRLRL,LR,LRLR,LRLRLR,RL,RLRL,LR,LRLR,RL,LR,共12条,所以输出为12

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
int n;
char s[];
int main()
{
n=read();
cin>>s;
int e=;
for(int i=;i<n;i++)
{
int a=,b=,c=,d=;
for(int j=i;j<n;j++)
{
if(s[j]=='U')
a++;
if(s[j]=='D')
b++;
if(s[j]=='L')
c++;
if(s[j]=='R')
d++;
if(a==b&&c==d)
e++;
}
}
cout<<e<<endl;
return ;
}

Codeforces 626A Robot Sequence(模拟)的更多相关文章

  1. Codeforces 626A Robot Sequence

    A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. 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 ...

  3. 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence 暴力

    A. Robot Sequence 题目连接: http://www.codeforces.com/contest/626/problem/A Description Calvin the robot ...

  4. A. Robot Sequence

    A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. UI自动化测试(四)AutoIT工具使用和robot对象模拟键盘按键操作

    AutoIT简介 AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/ ...

  6. Codeforces 601B. Lipshitz Sequence(单调栈)

    Codeforces 601B. Lipshitz Sequence 题意:,q个询问,每次询问给出l,r,求a数组[l,r]中所有子区间的L值的和. 思路:首先要观察到,斜率最大值只会出现在相邻两点 ...

  7. CodeForces - 224C. Bracket Sequence (栈模拟)简单做法

    A bracket sequence is a string, containing only characters "(", ")", "[&quo ...

  8. Codeforces.97D.Robot in Basement(bitset 模拟)

    题目链接 (ozr attack) 考虑怎么暴力,就是先在所有非障碍格子上全放上机器人,然后枚举每一步,枚举每个机器人移动这一步,直到所有机器人都在出口位置.复杂度是\(O(nmk)\)的. 怎么优化 ...

  9. Codeforces 916B Jamie and Binary Sequence ( 模拟 && 思维 )

    题意 : 给出一个数 n ,要求你用 k 个二的幂来组成这个数,要求输出这 k 个二的幂的指数,如果有多解情况则优先输出最大指数最小的那一个且要求按字典序输出,不存在则输出 No 分析 :  先来说一 ...

随机推荐

  1. loadrunner录制、加载以及分析过程

    loadrunner主要组件包括: Virtual User Generator(录制脚本,编写脚本直到调通) Controller(加载脚本,设计并发人数.监控点之类的,模拟场景,开始性能测试,最后 ...

  2. hibernate核心API使用

    1.Configuration 加载核心配置文件,核心配置文件名称和位置固定,否则会找不到 2.SessionFactory对象一个项目只创建一个,大家公用 根据配置文件和映射关系创建表 由于要创建表 ...

  3. nova创建虚拟机源码分析系列之四 nova代码模拟

    在前面的三篇博文中,介绍了restful和SWGI的实现.结合restful和WSGI配置就能够简单的实现nova服务模型的最简单的操作. 如下的内容是借鉴网上博文,因为写的很巧妙,将nova管理虚拟 ...

  4. C#中级-通过注册表读取Windows Service程序执行路径

    一.前言        假设我们的C#解决方案中有多个程序应用,如:Web应用.控制台程序.WPF程序应用和Windows服务应用. 那么这些非Windows Service应用程序怎么在代码中找到W ...

  5. du 命令详解

    du : show disk usage  作用:统计目录或文件所占用磁盘空间的大小. 语法:du 参数 选项 参数: -a 为每个制定文件显示磁盘使用情况, 或者为目录中每个文件显示各自磁盘使用情况 ...

  6. jquery提供的插件无法删除cookie的解决办法

    之前使用jquery的cookie插件提供的 $.cookie("key",null)方法删除cookie,结果发现代码中的cookie一直无法删除,导致后面的种种问题. 经过各种 ...

  7. Solr 管理界面删除所有数据

    https://my.oschina.net/lcdmusic/blog/326698

  8. KandQ:单例模式的七种写法及其相关问题解析

    设计模式中的单例模式可以有7种写法,这7种写法有各自的优点和缺点: 代码示例(java)及其分析如下: 一.懒汉式 public class Singleton { private static Si ...

  9. 一个好用的PHOTOSHOP切图插件(CutterMan插件下载)

    请关注CutterMan官方微博,分享本站点到自己微博中@Cutterman,私信TA,就有啦~~ 下载地址:http://www.cutterman.cn/ 也许你兴冲冲的下载了,然后发现安装不上, ...

  10. Git详解之六:Git工具

    Git 工具 现在,你已经学习了管理或者维护 Git 仓库,实现代码控制所需的大多数日常命令和工作流程.你已经完成了跟踪和提交文件的基本任务,并且发挥了暂存区和轻量级的特性分支及合并的威力.(伯乐在线 ...