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;
}
上一篇:Java多线程——同步(一)


下一篇:Magento 处理方法