zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    Linux系统安装Apache 2.4.6
    Redhat Server 5.7 安装配置PHP
    ORACLE基本数据类型总结
    Nagios学习实践系列——产品介绍篇
    Linux技术修复
    python的特殊方法:
    python获取对象信息
    python多重继承:
    python多态
    python类的继承
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11632900.html
Copyright © 2011-2022 走看看