codeforces 725A Jumping Ball(水)
来源:互联网 发布:高仿淘宝模板 编辑:程序博客网 时间:2024/06/05 20:50
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<cstdio>#include<cstring>const int maxn = 2e6 + 10;int main(){char s[maxn];int n;scanf("%d",&n);scanf("%s",s+1);int ans = 0;for(int i = 1; i <= n; i++){if(s[i] == '<') ans++; else break;}if(ans != n){for(int i = n; i >= 1; i--){ if(s[i] == '>') ans++; else break; }}printf("%d\n",ans);return 0; }
- codeforces 725A Jumping Ball(水)
- Codeforces 725A Jumping Ball
- CodeForces 725A Jumping Ball
- Codeforces 725 A Jumping Ball【水题】
- 725A Jumping Ball
- A. Jumping Ball
- Canada Cup 2016 A. Jumping Ball codeforces(水题)
- Canada Cup 2016 A - Jumping Ball (枚举水题)
- Canada Cup 2016 A - Jumping Ball
- code forces A. Jumping Ball (水题)
- Canada Cup 2016 A.Jumping Ball并查集 .
- CodeForces 203D Hit Ball 水!计算几何
- A simple bouncing ball
- A. Ball Game
- ROLL A BALL 小游戏
- Roll a Ball
- Roll a Ball
- CodeForces 11B - Jumping Jack
- C++primer学习笔记-第六章语句
- 属于自己的那首《一生所爱》
- python-Django每个应用中添加urls文件
- C语言经典算法09
- 1019日总结--滚动监听
- codeforces 725A Jumping Ball(水)
- sails-sockets-sample 消息推送
- ZooKeeper之(一)ZooKeeper是什么
- phpcms v9电脑pc站+手机wap移动端双模板共用数据库数据同步可同步生成静态文件
- json的取值方式
- 3.hibernate使用注解时发生的异常
- Ubuntu版微信
- C语言经典算法10
- JVM-1. 七个垃圾收集器的终极对比