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. pdf文件添加到word中

    今天遇到了一个问题,如何把pdf文件添加到word中,而不是只添加图标,下面是解决方案: 1.用word 打开pdf文件: 2.打开word文件: 3.把1中的pdf文件复制粘贴 到2中的word文件 ...

  2. 【转】cve-2013-2094 perf_event_open 漏洞分析

    cve-2013-2094是于2013年4月前后发现的linux kernel本地漏洞,该漏洞影响3.8.9之前开启了PERF_EVENT的linux系统.利用该漏洞,通过perf_event_ope ...

  3. java的集合类面试题

    转自:https://yq.aliyun.com/articles/78788?spm=5176.8252056.759076.3.uFYrmt java.util包中包含了一系列重要的集合类,而对于 ...

  4. 部署HBase系统(分布式部署)

    1.简介 HBase系统主要依赖于zookeeper和hdfs系统,所以部署HBase需要先去部署zookeeper和hadoop 2.部署开始 IP或者HOSTNAME需要根据自身主机信息设定. 部 ...

  5. tornado 模版

    tornado 模版语法 取消转义 : 取消项目转义 :autoescape = None 取消模版转义:{% autoescape None %} 取消行转义   :{% raw bd %} 强制转 ...

  6. Eclipse+Pydev+numpy+scipy+matplotlib

    之前一直在linux环境下使用python,作为一枚小菜还是更喜欢windows.我使用python主要是进行科学计算,安装软件.搭建环境遇到了非常多的问题,特此总结. 一.python安装 版本:2 ...

  7. HIbernate学习笔记2 之 主键生成方式

    一.hibernate主键生成方式: 1.常用方式:mysql:自增长生成主键(identity) <generator class="identity"> </ ...

  8. linux命令行任务管理

    今天看到了linux命令行的任务管理命令感觉很实用: 1.ctrl+z  将当前前台执行的任务放到后台并暂停 2.fg恢复上次放入后台的任务 这两个命令组合起来很实用,比如在linux命令行中写pyt ...

  9. False Positives和False Negative等含义

    True Positive (真正, TP)被模型预测为正的正样本: True Negative(真负 , TN)被模型预测为负的负样本 : False Positive (假正, FP)被模型预测为 ...

  10. HDR文件格式简介及其读写函数

    转自:http://blog.csdn.net/lqhbupt/article/details/7828827 1.HDR简介HDR的全称是High-DynamicRange(高动态范围).在此,我们 ...