267 字
1 分钟
Eating-Game

There are nn players playing a game at a circular table. The ii-th player has aia_i dishes to eat. They take turns eating the food, and any player can go first.

During their turn, if player ii has any dishes remaining, they must eat exactly one dish. Then, player (imodn)+1(i \bmod n) + 1 starts their turn. This continues until all dishes are finished.

The player who eats the last dish is considered the winner. Determine the number of players that can possibly be winners.

Input

The first line contains an integer tt (1t50001 \leq t \leq 5000), the number of test cases.

The first line of each test case contains an integer nn (1n101 \leq n \leq 10).

The second line of each test case contains nn integers, the elements of aa (1ai101 \leq a_i \leq 10).

Output

For each test case, output a line with the answer.

思路#

按题意,很明显这个“最有可能成为赢家”的玩家就是有最多菜的玩家,即:ai=amaxa_i = a_{max}

因此我们只需要统计出来有多少最大值的玩家就行了

代码#

#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t --) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i ++) cin >> a[i];
int M = *max_element(a.begin(), a.end());
int c = 0;
for (auto i: a) {
if (i == M) c ++;
}
cout << c << endl;
}
}
Eating-Game
https://github.com/posts/eating-game/
作者
FZSGBall
发布于
2026-05-08
许可协议
CC BY-NC-SA 4.0