codeforces A. Dreamoon and Ranking Collection

在这里插入图片描述

题目

题意:

给你一个 a a 序列代表每次的排名,在 n n 个比赛之后还有 x x 场比赛,然后你去寻找一个最大的 v v 代表这 n + x n+x 比赛后比赛的连续的最大的排名是多少。

思路:

这个题意感觉是真的难懂QAQ,比赛的时候看了好久,然后去开了第二题,但是只要读懂就很轻松了,我们可以用 c n t cnt 去记录此时的最高排名有没有出现过,如果没有的话,那就将 x x-- ,最后当 x = 0 x=0 并且 c n t cnt 此时最后排名没有出现过的话,那么前一个就是答案了。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void out(int x) {
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
int main() {
    int t, n, x;
    int a[110];
    read(t);
    while (t--) {
        int cnt[1010] = {0};
        read(n), read(x);
        for (int i = 0; i < n; i++) {
            read(a[i]);
            cnt[a[i]]++;
        }
        int k = 0;
        for (int i = 1; x; i++) {
            if (cnt[i] == 0) x--, k = i, cnt[i]++;
        }
        for (int i = k; ; i++) {
            if (cnt[i] == 0) {
                k = i - 1;
                break;
            }
        }
        printf("%d\n", k);
    }
}

发布了463 篇原创文章 · 获赞 27 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_45031646/article/details/105309258