8VC Venture Cup 2016 - Elimination Round A. Robot Sequence
来源:互联网 发布:淘宝如何修改会员名 编辑:程序博客网 时间:2024/04/30 02:51
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list ofn 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.
6URLLDR
2
4DLUU
0
7RLRLRLR
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.
题意:给你一个字符串,里面有UDLR,分别表示四个方向,问这个串的连续子串有多少是能使其回到起点的。。
思路:直接暴力枚举就好了
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<set>#include<queue>#include<vector>#define MAXN 1010000#define LL long long#define ll __int64#include<iostream>#include<algorithm>#define INF 0xfffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)using namespace std;LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}LL lcm(LL a,LL b){return a/gcd(a,b)*b;}LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}//headint main(){int len;char s[222];while(scanf("%d",&len)!=EOF){scanf("%s",s);int cnt=0;for(int i=0;i<len;i++){for(int j=i+1;j<len;j++){int x=1,y=1;for(int k=i;k<=j;k++){if(s[k]=='U')y++;else if(s[k]=='D')y--;else if(s[k]=='L')x--;elsex++;}if(x==1&&y==1)cnt++;}}printf("%d\n",cnt);}return 0;}
- 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence
- 8VC Venture Cup 2016 - Elimination Round-A. Robot Sequence(模拟)
- 8VC Venture Cup 2016 - Elimination RoundA. Robot Sequence
- 8VC Venture Cup 2016 -A - Robot Sequence/B - Cards
- 8VC Venture Cup 2017 - Elimination Round(A+B)
- 8VC Venture Cup 2017 - Elimination Round
- 8VC Venture Cup 2016 - Elimination Round题解
- Codeforces 8VC Venture Cup 2016 - Elimination Round解题报告
- 8VC Venture Cup 2016 - Elimination Round 总结
- 8VC Venture Cup 2016 - Elimination Round C - Block Towers
- Codeforces 8VC Venture Cup 2016 - Elimination Round
- 8VC Venture Cup 2016 - Elimination Round总结
- 8VC Venture Cup 2016 - Elimination Round C. Block Towers
- Codeforces 8VC Venture Cup 2017 - Elimination Round
- 8VC Venture Cup 2016 - Elimination Round (626A,626B,626C(二分),626D(概率))
- 8VC Venture Cup 2017 - Elimination Round A. PolandBall and Hypothesis【水题】
- 8VC Venture Cup 2017 - Elimination Round (先更A-B-C题)
- 解题报告:8VC Venture Cup 2016 — Elimination Round C.Block Towers
- Visual Studio 2008 可扩展性开发(五):操作Solution、Project和ProjectItem
- 【杂谈】MATLAB插值方法简介
- JavaWeb学习总结(二)——Tomcat服务器学习和使用(一)
- jquery ajax No 'Access-Control-Allow-Origin' header is present on the requested resource
- nginx referer限制
- 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence
- android pull 解析xml文件
- Python语言实践分析 -- 默认参数
- 【JS学习笔记】内置对象
- Visual Studio 2008 可扩展性开发(六):操作Solution Explorer
- 8VC Venture Cup 2016 - Elimination Round B. Cards (隐式图DFS)
- struts2拦截器配置详解
- p277 第十章 数组和指针
- Spark源码分析之一:Job提交运行总流程概述