Codeforces 626 A. Robot Sequence (8VC Venture Cup 2016-Elimination Round)
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 main(){
char a[];
int t,m,n,h,l,ans;
while(~scanf("%d",&t)){
scanf("%s",&a);
ans=;
for(int i=;i<t;i++){
m=;n=;h=;l=;
for(int j=i;j<t;j++){
if(a[j]=='U') m++;
if(a[j]=='D') n++;
if(a[j]=='L') h++;
if(a[j]=='R') l++;
if(m==n&&h==l) ans++;
}
}
printf("%d\n",ans);
}
return ;
}
Codeforces 626 A. Robot Sequence (8VC Venture Cup 2016-Elimination Round)的更多相关文章
- 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence 暴力
A. Robot Sequence 题目连接: http://www.codeforces.com/contest/626/problem/A Description Calvin the robot ...
- 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 C. Lieges of Legendre
C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...
- Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****
F. Group Projects There are n students in a class working on group projects. The students will div ...
- 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)
题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...
- 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树
G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...
- 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 ...
- 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分
E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...
- 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 ...
随机推荐
- StrutsResultSupport的使用
在有特殊情况时:如果没有异常信息,但是有错误并且有错误信息等内容:此时也需要进行友好的错误处理的话,那么可以借助StrutsResultSupport 返回结果类型来实现特定处理.此种方式先需要继承S ...
- IIS 发布后无法连接数据库(应用池问题)
查找网站对应的 应用池,修改为 .net4.0 然后设置启动32位应用程序为 True
- Ubuntu下使用find / -name aaa* 提示“find: 路径必须在表达式之前: XXXX”
在使用find命令查找文件时,出现了如题所示的错误提示,因为之前都是这样用的,也没出过错,这次语法都是一样的居然不行了,很是纳闷. 后来了解到如下的情况: 如果当前所在目录存在要查找的目标文件时会出现 ...
- 使用Spring AOP实现读写分离(MySql实现主从复制)
1. 背景 我们一般应用对数据库而言都是“读多写少”,也就说对数据库读取数据的压力比较大,有一个思路就是说采用数据库集群的方案,其中一个是主库,负责写入数据,我们称之为:写库: 其它都是从库,负责读 ...
- C++开源库,欢迎补充。
转载自:http://blog.csdn.net/kobejayandy/article/details/8681741 C++在"商业应用"方面,曾经是天下第一的开发语言,但这一 ...
- 布局之BFC
BFC 什么是BFC,在哪里需要用到BFC,BFC有什么规则?生成BFC有什么条件?这几个问题,我将为大家一一解释,下面我们进入正题. BFC(Block formatting context)直译为 ...
- 1552: [Cerc2007]robotic sort
这道题用splay写 先离散化数据保证按题目所述顺序来写 按原序作为键值建树 维护区间最小值去跑 每次将i的位置 和 n的位置x和y找出来后 将x旋转到root y旋转到x的有儿子 这时y的左子树就是 ...
- SSM初步整合一
SSM(spring+springmvc+mybatis)初步整合一配置步骤: 步骤一.导入所需jar包 步骤二 .配置web.xml文件 <?xml version="1.0&quo ...
- 使用Frida简化Android端应用安全测试
@author : Dlive 在对Android应用进行Web漏洞测试时,经常遇到一种情况:HTTP传输的数据带有签名字段 处理这种情况的方法通常是逆向签名算法,但是如果算法在so中,而且so加壳了 ...
- Selenium菜鸟手册
转自: http://www.iselenium.com/read.php?tid=458 首先声明我还是一只很菜的菜鸟,学习Selenium一个来月而已,发这个帖子是想利用我这块板砖引出真正的玉来, ...