8VC Venture Cup 2016 - Elimination Round A. Robot Sequence 暴力
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 暴力的更多相关文章
- 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
在家补补题 模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...
- 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 ...
- 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)
题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...
- 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 + ...
- 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题
F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...
- 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 C. Block Towers 二分
C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...
随机推荐
- Yii 1.1.17 六、开启路由与使用缓存
一.开启路由 1.在配置文件main.php的components中 定义如下: // 定义路由 'urlManager'=>array( // URL模式为PATHINFO 'urlForma ...
- Makefile parameters pass 參數傳遞
command $make ARCH=7777777777777777777777777777777 Makefile content $(warning $(ARCH)) output Makefi ...
- Win10默认图片查看器更改
Win10自带的图片查看器不是很习惯,其背景乌漆嘛黑,宽扁的额头让人想起了黑边火腿肠手机,无法直视.怀念Win7和Win8.1的图片查看器,一个鼠标滚轮缩放自如的酸爽感觉.但却遗憾地发现,并不能直观地 ...
- 改变ASPxpivotgridview弹出的prefilter的标题
说是要给变标题,再网上找了很久的资料,基本上属于一无所获,后来在官网上看到一个技术支持用vb写的,说是要本地化什么的,个人技术有限不是太懂 后来干脆就直接注册个账号,发问了,好歹等到了晚上十点左右,有 ...
- pxe+kickstart自动化安装
什么是PXE? PXE(Pre-boot Execution Environment,预启动执行环境)是Intel公司开发的最新技术,工作于Client/Server模式.PXE是一种远程引导方式,要 ...
- C++智能指针: auto_ptr, shared_ptr, unique_ptr, weak_ptr
本文参考C++智能指针简单剖析 内存泄露 我们知道一个对象(变量)的生命周期结束的时候, 会自动释放掉其占用的内存(例如局部变量在包含它的第一个括号结束的时候自动释放掉内存) int main () ...
- 简单理解Hash算法的作用
什么是Hash Hash算法,简称散列算法,也成哈希算法(英译),是将一个大文件映射成一个小串字符.与指纹一样,就是以较短的信息来保证文件的唯一性的标志,这种标志与文件的每一个字节都相关,而且难以找到 ...
- css设置div等标签背景半透明
三种方式: 1. background-color: transparent; 直接设置背景为透明 2.这种是子元素也会跟着变成半透明 /* 背景半透明,1为不透明 */ opacity: 0.5; ...
- 解决Myeclipse编译不生成.class文件问题
1.Project --> clean... 如果该操作无效,请执行2. 2.Preferences -->Java -->Compliler -->Building --& ...
- redis 安装配置
reids 安装配置 1.1 下载软件包 [root@node01 ~]# mkdir -p /data/src/ [root@node01 ~]# cd /data/src/ [root@node0 ...