Codeforces-8VC Venture Cup 2016-Elimination Round-626A.暴力 626B.水题 626C.二分
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-8VC Venture Cup 2016-Elimination Round-626A.暴力 626B.水题 626C.二分的更多相关文章
- 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 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 ...
- 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 C. Block Towers 二分
C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...
- 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞
B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...
- 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence 暴力
A. Robot Sequence 题目连接: http://www.codeforces.com/contest/626/problem/A Description Calvin the robot ...
随机推荐
- C#扩展(2):Random的扩展
在.net中关于Random一共也只有这几个方法 // // 摘要: // 表示伪随机数生成器,一种能够产生满足某些随机性统计要求的数字序列的设备. [ComVisible(true)] public ...
- ArcGIS API for JavaScript 4.2学习笔记[24] 【IdentifyTask类】的使用(结合IdentifyParameters类)(第七章完结)
好吧,我都要吐了. 接连三个例子都是类似的套路,使用某个查询参数类的实例,结合对应的Task类,对返回值进行取值.显示. 这个例子是Identify识别,使用了TileLayer这种图层,数据来自Se ...
- 解决linux重启后无法开启nginx问题“var/run/nginx/nginx.pid" no such file or directory问题
起因:每次重启虚拟机后,var/run/nginx/目录都会被删除,所以无法在这个目录创建nginx.pid文件, 可以自己创建var/run/nginx/目录,然后可以运行,但治标不治本,下次虚拟机 ...
- tomcat部署项目时省略项目名
大家也许知道在eclipse上通过新建server来部署项目到tomcat,并且通过server来管理项目的启动配置.server会自动创建启动该项目的xml 如: <Context docBa ...
- IE下判断IE版本的语句...[if lte IE 8]……[endif]
<!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if lte IE 7]> <![endif]--> ...
- 使用svn 的解决 处理svn状态冲突
当直接只用版本浏览器进行svn的删除操作是,在客户端svn目录里,出现svn版本错误信息提示,使用 svn 解决命令,处理冲突保存 svn resolve --accept=working PATH( ...
- Xamarin.Android 引导页
http://blog.csdn.net/qq1326702940/article/details/78665588 https://www.cnblogs.com/catcher1994/p/555 ...
- Python学习_02_数字和运算
python具有强大的科学运算功能,python由于支持更加强大的面向对象和动态特性,相比R语言.matlab.mathmatic等传统的科学计算工具具有非常大的优势. Python的数字 pytho ...
- Fiddler的hosts配置使用
前提:使用fiddler的hosts配置,可以方便的配置自己想要测试环境,不需要每次配置hosts都到windows目录下去修改hosts文件 1.点击Tool->HOSTS,打开hosts的配 ...
- 初步了解 Django Models
Part1:了解主键 1. Python和Django版本如下: E:\django>python3 -V Python 3.5.2 E:\django>python3 -m d ...