• Codeforces Round #585 (Div. 2) A. Yellow Cards(数学)


    链接:

    https://codeforces.com/contest/1215/problem/A

    题意:

    The final match of the Berland Football Cup has been held recently. The referee has shown n yellow cards throughout the match. At the beginning of the match there were a1 players in the first team and a2 players in the second team.

    The rules of sending players off the game are a bit different in Berland football. If a player from the first team receives k1 yellow cards throughout the match, he can no longer participate in the match — he's sent off. And if a player from the second team receives k2 yellow cards, he's sent off. After a player leaves the match, he can no longer receive any yellow cards. Each of n yellow cards was shown to exactly one player. Even if all players from one team (or even from both teams) leave the match, the game still continues.

    The referee has lost his records on who has received each yellow card. Help him to determine the minimum and the maximum number of players that could have been thrown out of the game.

    思路:

    最少的就是先给每个人k-1张, 再慢慢补, 最多的就是贪心给, 先给k小的.

    代码:

    #include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        int a1, a2, k1, k2, n;
        cin >> a1 >> a2 >> k1 >> k2 >> n;
        if (k1 > k2)
            swap(a1, a2), swap(k1, k2);
        int sum = a1*(k1-1)+a2*(k2-1);
        int small = max(0, min(a1+a2, n-sum));
        int cnta = min(a1, n/k1);
        n -= cnta*k1;
        int cntb = min(a2, n/k2);
        cout << small << ' ' << cnta+cntb << endl;
     
        return 0;
    }
    
  • 相关阅读:
    lower_bound和upper_bound
    memcache教程
    php header() 函数
    修复TortoiseGit文件夹和文件图标不显示
    mysql数据类型
    PDO类PDO、PDOStatement、PDOException
    mysqli和pdo对mysql数据库的操作
    php 关键字
    几个入口文件定义函数
    php --魔术常量 /魔术方法
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11632900.html
Copyright © 2020-2023  润新知