A. Robot Sequence

题目连接:

http://www.codeforces.com/contest/626/problem/A

Description

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.

Sample Input

6

URLLDR

Sample Output

2

Hint

题意

给你一个命令,然后让你输出这个命令中有多少个子串的起点和终点是一样的

题解:

数据范围只有200,所以直接n^2暴力就好了

记录一下前缀和。

其实不记录前缀和 n^3也是兹瓷的

代码

#include<bits/stdc++.h>
using namespace std; const int maxn = 503;
char s[maxn];
int x[maxn],y[maxn]; int main()
{
int n;
scanf("%d",&n);
scanf("%s",s+1);
for(int i=1;i<=n;i++)
{
x[i]=x[i-1];
y[i]=y[i-1];
if(s[i]=='U')x[i]++;
if(s[i]=='D')x[i]--;
if(s[i]=='L')y[i]++;
if(s[i]=='R')y[i]--;
}
int ans = 0;
for(int i=0;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(x[i]-x[j]==0&&y[i]-y[j]==0)
ans++;
cout<<ans<<endl;
}

8VC Venture Cup 2016 - Elimination Round A. Robot Sequence 暴力的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  2. 8VC Venture Cup 2016 - Elimination Round

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

  3. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

  4. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  5. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  6. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  7. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  8. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  9. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

随机推荐

  1. 【Python问题解决】关于解决python3.x无法使用PIL库的解决方法

    因为PIL库目前只更新到python2.x,故python3.x直接安装PIL库会找不到版本.但是python3.x有一个新的库,可以提供和PIL差不多的功能,也就是pillow库. 本人使用的是py ...

  2. 为什么Windows7打开项目的方式是灰的不能修改

    http://jingyan.baidu.com/article/d3b74d64a964691f77e60900.html 进入组策略编辑器,即运行gpedit.msc,进入“用户配置”-“管理模板 ...

  3. sicily 数据结构 1014. Translation

    Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...

  4. freemark学习

    学习地址: http://blog.csdn.net/hejinxu/article/details/6694890   对freemarker的用法与语法进行了详细的讲解 http://freema ...

  5. jQuery -《锋利的jQuery》————读后小结

    jQuery是一个优秀的javascript库. 我用的是vs2012自带的  jquery-1.8.2.js这个库,在Scripts这个文件夹下面 首先,我们使用jQuery要在head标签内引入j ...

  6. java中的Map集合

    Map接口 Map为一个接口.实现Map接口的类都有一个特点:有键值对,将键映射到值的对象. Map不能包含重复的键,每个键可以映射到最多一个值. Map常见的接口方法有: V  put(K key, ...

  7. HDU 2829 Lawrence(斜率优化DP O(n^2))

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2829 题目大意:有一段铁路有n个站,每个站可以往其他站运送粮草,现在要炸掉m条路使得粮草补给最小,粮草 ...

  8. 883H - Palindromic Cut(思维+STL)

    题目链接:http://codeforces.com/problemset/problem/883/H 题目大意:给一段长度为n的字符串s,想让你把s切成几段长度相同的回文串,可以改变s中字符的排列, ...

  9. 自定义wordCount程序、

    1.MyWordCount代码: package com.hadoop.mr; import java.io.IOException; import org.apache.hadoop.conf.Co ...

  10. SQL Server 2008的MSSQLSERVER 请求失败或服务未及时响应

    我的是SQL server 2008R2, 以前可以正常的启动SQL server(SQLEXPRESS).SQL server(MSSQLSERVER),有几天没有打开了,就在昨天 开机之后就无法启 ...