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.

#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的更多相关文章

  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 626A Robot Sequence(模拟)

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

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

  5. 前端自动化测试工具doh学习总结(二)

    一.robot简介 robot是dojo框架中用来进行前端自动化测试的工具,doh主要目的在于单元测试,而robot可以用来模仿用户操作来测试UI.总所周知,Selenium也是一款比较流行的前端自动 ...

  6. 8VC Venture Cup 2016 - Elimination Round

    在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...

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

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

  9. CSUFT 1002 Robot Navigation

    1002: Robot Navigation Time Limit: 1 Sec      Memory Limit: 128 MB Submit: 4      Solved: 2 Descript ...

随机推荐

  1. 第三方br查询工具害人不浅

    第三方br查询工具害人不浅,查询的时候会大批量调用百度的数据库,为什么说是大批量查询呢? 首先是自己查询,心急的站长恨不得下一次刷新br时数值会有所提高,不是那么急的也会一天查一次或几天一次,记录网站 ...

  2. Hadoop之伪分布环境搭建

    搭建伪分布环境 上传hadoop2.7.0编译后的包并解压到/zzy目录下 mkdir /zzy 解压 tar -zxvf hadoop.2.7.0.tar.gz -C /zzy     配置hado ...

  3. PHP error_log() 函数

    定义和用法 error_log() 函数向服务器错误记录.文件或远程目标发送一个错误. 若成功,返回 true,否则返回 false. 语法 error_log(error,type,destinat ...

  4. [Effective JavaScript 笔记]第27条:使用闭包而不是字符串来封装代码

    函数是一种将代码作为数据结构存储的便利方式,代码之后可以被执行.这使得富有表现力的高阶函数抽象如map和forEach成为可能.它也是js异步I/O方法的核心.与此同时,也可以将代码表示为字符串的形式 ...

  5. UITableView 学习笔记

    http://www.cnblogs.com/smileEvday/archive/2012/06/28/tableView.html UITableView学习笔记 作者:一片枫叶 看TableVi ...

  6. linux 文件权限除了r、w、x外还有s、t、i、a权限:

    s:文件属主和组设置SUID和GUID,文件在被设置了s权限后将以root身份执行.在设置s权限时文件属主.属组必须先设置相应的x权限,否 则s权限并不能正真生效(c h m o d命令不进行必要的完 ...

  7. poj 3020 最短路径覆盖 Antenna Placement

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7329   Accepted: 3635 ...

  8. 【架构】浅谈web网站架构演变过程

    浅谈web网站架构演变过程   前言 我们以javaweb为例,来搭建一个简单的电商系统,看看这个系统可以如何一步步演变.   该系统具备的功能:   用户模块:用户注册和管理 商品模块:商品展示和管 ...

  9. 【OpenStack】OpenStack系列6之Sheepdog环境搭建

    准备 repo配置 yum clean all yum makecache yum install -y make automake autoconf gcc nss-devel wget git g ...

  10. table动态添加删除一行和改变标题

    <style type="text/css"> body{ font-size:13px; line-height:25px; } table{ border-top: ...