Canada Cup 2016 A - Jumping Ball
来源:互联网 发布:淘宝电影票怎么退 编辑:程序博客网 时间:2024/05/16 05:45
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 ori + 1 > n, the ball falls from the game field.
Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position.
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
4<<><
2
5>>>>>
5
4>><<
0
In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field.
思路:超级简单,当初就是想复杂了,还是思路不够明确,就是有哪几个位置从此走可以走出来。
代码:
#include<stdio.h>#include<cstring>#include<iostream>#include<algorithm>#include<math.h>#include<stdlib.h>#include<stack>#include<vector>#include<string.h>#include<map>#define INF 0x3f3f3f3f3fusing namespace std;char a[200009];int main(){ int n; while(~scanf("%d",&n)) { scanf("%s",a); int l=strlen(a); int p=0,p1=n-1; while(p<n&&a[p]=='<')//前面只有<才可以从左边走出来,所以在左边有几个连续的<就证明有几个位置 { p++; } //printf("%d\n",p); while(p1>=0&&a[p1]=='>')//后面只有>才可以从右边走出来,所以从右边的第一个开始有几个>就证明有几个满足条件的位置 {//("##\n"); p1--; } //printf("%d\n",p1); printf("%d\n",p+n-1-p1);//答案就是两个结果的相加 }}做题还是多思考,不会还是刷的题不够。。。
- Canada Cup 2016 A - Jumping Ball
- Canada Cup 2016 A.Jumping Ball并查集 .
- Canada Cup 2016 A. Jumping Ball codeforces(水题)
- Canada Cup 2016 A - Jumping Ball (枚举水题)
- codeforces Canada cup 2016 A~D
- Canada Cup 2016
- Canada Cup 2016 E
- Canada Cup 2016
- A. Jumping Ball
- 725A Jumping Ball
- CodeForces Canada Cup 2016【A,B,C,D】
- Canada Cup 2016 A,B,C,D,E
- Canada Cup 2016 C 模拟
- Codeforces 725A Jumping Ball
- CodeForces 725A Jumping Ball
- CodeForces Canada Cup 2016 A、B水题 _(:з」∠)_
- Canada Cup 2016 C. Hidden Word .
- Canada Cup 2016 D. Contest Balloons
- Android应用性能测试之cpu和内存占用
- 按应用领域划分的操作系统
- 想系统的学习一下项目管理,有什么好的书籍推荐吗?
- Java时间日期
- html引号里加引号
- Canada Cup 2016 A - Jumping Ball
- 浮点数高斯消元的模板
- android中WebView关闭打开第三方浏览器
- Git中remote、fetch、pull、push命令介绍
- js的BOM
- Android MVP模式(上篇-简单应用)
- JVM浅入
- sublime text3 安装package control 管理插件
- 游戏社交不足怎么办? 游戏发行中的社交化运营经验分享