#abc256b. B - Batters
B - Batters
Score : points
问题描述
高桥正在尝试制作一款受棒球启发的游戏,但在编写代码时遇到了困难。 为高桥编写一个程序,解决以下问题。
有四个正方形分别称为 Square 、Square 、Square 和 Square 。最初,所有正方形都是空的。 还有一个整数 ;初始时,。 给定一个正整数序列 ,按照 的顺序执行以下操作:
- 在 Square 上放置一个棋子。
- 将正方形上每个棋子向前移动 个格子。也就是说,如果 Square 上有一个棋子,则将该棋子移动到 Square 。 然而,如果某个棋子的目标格子不存在(即 大于或等于 ),则移除该棋子。并将被移除的棋子数量加到 上。
在所有操作完成后,输出 的值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi is trying to create a game inspired by baseball, but he is having difficulty writing the code.
Write a program for Takahashi that solves the following problem.
There are squares called Square , Square , Square , and Square . Initially, all squares are empty.
There is also an integer ; initially, .
Given a sequence of positive integers , perform the following operations for in this order:
- Put a piece on Square .
- Advance every piece on the squares squares ahead. In other words, if Square has a piece, move the piece to Square .
If, however, the destination square does not exist (i.e. is greater than or equal to ) for a piece, remove it. Add to the number of pieces that have been removed.
Print the value of after all the operations have been performed.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the value of after all the operations have been performed.
Sample Input 1
4
1 1 3 2
Sample Output 1
3
The operations are described below. After all the operations have been performed, equals .
- The operations for :
- Put a piece on Square . Now, Square has a piece.
- Advance every piece on the squares square ahead. After these moves, Square has a piece.
- The operations for :
- Put a piece on Square . Now, Squares and have a piece.
- Advance every piece on the squares square ahead. After these moves, Squares and have a piece.
- The operations for :
- Put a piece on Square . Now, Squares , , and have a piece.
- Advance every piece on the squares squares ahead.
Here, for the pieces on Squares and , the destination squares do not exist (since and ), so remove these pieces and add to . now equals . After these moves, Square has a piece.
- The operations for :
- Put a piece on Square . Now, Squares and have a piece.
- Advance every piece on the squares squares ahead.
Here, for the piece on Square , the destination square does not exist (since ), so remove this piece and add to . now equals .
After these moves, Square has a piece.
Sample Input 2
3
1 1 1
Sample Output 2
0
The value of may not be updated by the operations.
Sample Input 3
10
2 2 4 1 1 1 4 2 2 1
Sample Output 3
8
update @ 2024/3/10 10:53:08