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 ...
随机推荐
- JS判断客户端是否是iOS或者Android手机移动端
var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > - ...
- artdialog自定义多个按钮
在实际运用到的过程中artdialog弹出框下面的按钮不止一个 可以自己定义多个按钮 function view_show(cust_id){$.dialog({ id: 'view_c ...
- python初学-元组、集合
元组: 元组基本和列表一样,区别是 元组的值一旦创建 就不能改变了 tup1=(1,2,3,4,5) print(tup1[2]) ---------------------------------- ...
- P1474 货币系统 Money Systems(完全背包求填充方案数)
题目链接:https://www.luogu.org/problemnew/show/1474 题目大意:有V种货币,求用V种货币凑出面值N有多少种方案. 解题思路:就是完全背包问题,只是将求最大价值 ...
- hdu 2444(染色法判断二分图+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- Django学生管理系统添加学生时,报错Not Found: /POST
最近在学习Django,跟着视频写了一个学生系统,主要是增删改查操作,界面丑的一匹 1.url.py from django.contrib import admin from django.urls ...
- 微软企业库5.0 学习之路——第二步、使用VS2010+Data Access模块建立多数据库项目
现在我就开始进入学习之路的第二步——Data Access模块,这个模块是企业库中被使用频率最高的模块,它很好的封装了数据库操作应用,为我们进行多数据库系统开发提供了便利,只需更改配置文件就 可以很快 ...
- spring.net 在demo中的分析
1.认识spring.net Spring.NET是一个应用程序框架,其目的是协助开发人员创建企业级的.NET应用程序.它提供了很多方面的功能,比如依赖注入.面向方面编程(AOP).数据访问抽象及AS ...
- 运行hadoop的时候提示物理内存或虚拟内存溢出的解决方案running beyond physical memory或者beyond vitual memory limits
当运行中出现Container is running beyond physical memory这个问题出现主要是因为物理内存不足导致的,在执行mapreduce的时候,每个map和reduce都有 ...
- java原理—反射机制
http://www.cnblogs.com/forlina/archive/2011/06/21/2085849.html 一.什么是反射:反射的概念是由Smith在1982年首次提出的,主要是指程 ...