Codeforces Round 902 (Div. 2) 题解 A-C

A - Goals of Victory

原题链接

题目描述
总共有n个球队,两两进行比赛,每个队每场比赛的得分为当场比赛总进球数减去对手在当场比赛中的总进球数,现在给出前n-1个队伍每个队伍的最终得分,请你求出第n个球队的得分。

思路:模拟

  • 1和剩余的得分值直接模拟每个球队得分的得与失,直至将每个队的得分模拟至0
public static void solve() throws IOException {
    int n = readInt();
    int[] ef = new int[n + 10];
    for (int i = 1; i <= n - 1; i++) {
        ef[i] = readInt();
    }
    int[][] match = new int[n + 10][n + 10];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            match[i][j] = inf;
        }
    }
    for (int i = 1; i <= n - 1; i++) {
        for (int j = 1; j <= n; j++) {
            if (match[i][j] == inf && i != j) {
                if (ef[i] > 0) {
                    if (j != n) {
                        match[i][j] = 1;
                        match[j][i] = -1;
                        ef[j]++;
                        ef[i]--;
                    } else {
                        match[i][j] = ef[i];
                        match[j][i] = -ef[i];
                        ef[j] += ef[i];
                        ef[i] = 0;
                    }
                } else if (ef[i] < 0) {
                    if (j != n) {
                        match[i][j] = -1;
                        match[j][i] = 1;
                        ef[j]--; ef[i]++;
                    } else {
                        match[i][j] = ef[i];
                        match[j][i] = -ef[i];
                        ef[j] -= ef[i]; ef[i] = 0;
                    }
                } else {
                    match[i][j] = 0;
                    match[j][i] = 0;
                }
            }
        }
    }
    int sum = 0;
    for (int i = 1; i <= n - 1; i++) {
        sum += match[n][i];
    }
    printWriter.println(sum);
}

B - Helmets in Night Light

原题链接

题目描述
你是村长,可以直接将公告发给一位或多位居民,发给每人需要花费 p p p。已知公告的第 i i i个居民可以将公告再发给 a i a_i ai个居民,发给每人需要花费 b i b_i bi,现请你求出如果要让 n n n个居民都知道公告,最低费用为多少。

思路:排序

  • 不断将 b i b_i bi值较小的入队,如果 b i b_i bi大于了 p p p,那么花费肯定更高,直接break
public static void solve() throws IOException{
    int n = readInt(), p = readInt();
    Pair[] pairs = new Pair[n + 10];
    for (int i = 1; i <= n; i++) {
        pairs[i] = new Pair();
        pairs[i].first = readInt();
    }
    for (int i = 1; i <= n; i++) {
        pairs[i].second = readInt();
    }
    long total = 1l * n * p;
    Arrays.sort(pairs, 1, n + 1, new Comparator<Pair>() {
        @Override
        public int compare(Pair o1, Pair o2) {
            if (o1.second == o2.second) {
                return o2.first - o1.first;
            }
            return o1.second - o2.second;
        }
    });
    Deque<Pair> deque = new LinkedList<>();
    deque.offer(pairs[1]);
    int cur = 1;
    while (deque.size() > 0) {
        Pair pair = deque.poll();
        if (pair.second < p) {
            int t = cur + pair.first;
            for (int i = cur + 1; i <= t && i <= n; i++) {
                total -= (p - pair.second);
                deque.offer(pairs[i]);
                cur = i;
            }
        } else {
            break;
        }
    }
    printWriter.println(total);
}

C - Joyboard

原题链接

题目描述
一个屏幕有 n + 1 n + 1 n+1个插槽,你需要在第 n + 1 n + 1 n+1和插槽的位置填入一个 0 ∼ m 0 \sim m 0m的数,使得屏幕上所有插槽总共正好显示 k k k个不同的数,屏幕上 1 ∼ n 1 \sim n 1n位置上的插槽上显示的数为 a i = a i + 1 m o d   i a_i = a_{i + 1} mod \ i ai=ai+1mod i,请你求出在插槽 n + 1 n + 1 n+1的位置上有多少种方案可以满足上述条件。

思路:分类讨论

  • 假设在 n + 1 n+1 n+1的位置插入元素为 x x x
  • x = 0 x = 0 x=0, 只有一种数字
  • x > 0   & &   x ≤ n x \gt 0 \ \&\& \ x \leq n x>0 && xn时,只有 0 0 0 x x x这两种数字
  • x > n x \gt n x>n时,如果 x x x n n n的倍数,只有 0 0 0 x x x这两种数字,否则总共有 3 3 3种数字。
public static void solve() throws IOException{
    int n = readInt(), m = readInt(), k = readInt();
    if (k == 1) {
        printWriter.println(m >= 0 ? 1 : 0);
    } else if (k == 2) {
        if (m == 0) {
            printWriter.println(0);
        } else if (m <= n) {
            printWriter.println(m);
        } else {
            printWriter.println(n - 1 + m / n);
        }
    } else if (k == 3) {
        if (m >= n) {
            printWriter.println(m - n - m / n + 1);
        } else {
            printWriter.println(0);
        }
    } else {
        printWriter.println(0);
    }
}
抱歉,根据提供的引用内容,我无法理解你具体想要问什么问题。请提供更清晰明确的问题,我将竭诚为你解答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【CodeforcesCodeforces Round 865 (Div. 2) (补赛)](https://blog.csdn.net/t_mod/article/details/130104033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值