练习cf1487A. Arena

题目如下
A. Arena
time limit per test1 second
memory limit per test256 megabytes
𝑛 heroes fight against each other in the Arena. Initially, the 𝑖-th hero has level 𝑎𝑖.

Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it's even possible that it is the same two heroes that were fighting during the last minute).

When two heroes of equal levels fight, nobody wins the fight. When two heroes of different levels fight, the one with the higher level wins, and his level increases by 1.

The winner of the tournament is the first hero that wins in at least 100500fights (note that it's possible that the tournament lasts forever if no hero wins this number of fights, then there is no winner). A possible winner is a hero such that there exists a sequence of fights that this hero becomes the winner of the tournament.

Calculate the number of possible winners among 𝑛 heroes.

Input
The first line contains one integer 𝑡 (1≤𝑡≤500) — the number of test cases.

Each test case consists of two lines. The first line contains one integer 𝑛 (2≤𝑛≤100) — the number of heroes. The second line contains 𝑛 integers 𝑎1,𝑎2,…,𝑎𝑛 (1≤𝑎𝑖≤100), where 𝑎𝑖 is the initial level of the 𝑖-th hero.

Output
For each test case, print one integer — the number of possible winners among the given 𝑛 heroes.

题目大意
现在n位英雄参加比赛,每个人初始等级为ai,每两名英雄之间可以互相进行决赛,等级高的人会胜出这一局比赛,但输的人也不会被淘汰,只要满足一名英雄赢够100的500次 场比赛那么他就是胜出者,输出可能的胜者的人数。

题目分析
换言之,只要不是等级最低的都可能胜出。
统计大于最低等级的人数即可。

点击查看代码
#include <iostream>
#include <vector>
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 min = a[0];
        for(int i = 1; i < n; i++){
            if(a[i] < min){
                min = a[i];
            }
        }
        int cnt = 0;
        for(int i = 0; i < n; i++){
            if(a[i] > min){
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}
posted @ 2025-07-18 21:52  sirro1uta  阅读(13)  评论(0)    收藏  举报