http://www.yyycode.cn/index.php/2020/05/30/a-berland-poker/
The game of Berland poker is played with a deck of nn cards, mm of which are jokers. kk players play this game (nn is divisible by kk).
At the beginning of the game, each player takes nknk cards from the deck (so each card is taken by exactly one player). The player who has the maximum number of jokers is the winner, and he gets the number of points equal to x−yx−y, where xx is the number of jokers in the winner’s hand, and yy is the maximum number of jokers among all other players. If there are two or more players with maximum number of jokers, all of them are winners and they get 00 points.
Here are some examples:
Given nn, mm and kk, calculate the maximum number of points a player can get for winning the game.Input
The first line of the input contains one integer tt (1≤t≤5001≤t≤500) — the number of test cases.
Then the test cases follow. Each test case contains three integers nn, mm and kk (2≤n≤502≤n≤50, 0≤m≤n0≤m≤n, 2≤k≤n2≤k≤n, kk is a divisors of nn).Output
For each test case, print one integer — the maximum number of points a player can get for winning the game.ExampleinputCopy
4 8 3 2 4 2 4 9 6 3 42 0 7
outputCopy
3 0 1 0
Note
Test cases of the example are described in the statement.
题意:有n张牌,m张小丑,有k个人,保证n/k整除。给第一个人分配最多的小丑牌,给其他人分配小丑牌,问第一个人的小丑牌-其他人中最大的小丑牌是多少?
思路:贪心优先给第一个人在条件允许的情况下分配最多的小丑牌,然后给剩下的人平摊小丑牌。注意一下一些特殊情况
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e5;
typedef long long LL;
LL a[maxn];
int main(void)
{
LL t; cin>>t;
while(t--)
{
LL n,m,k;cin>>n>>m>>k;
if(m==0) cout<<"0"<<endl;
else if(n/k>=m)
{
cout<<m<<endl;
}
else if(n/k<m)
{
if ( (m-n/k)%(k-1)==0 )
{
LL p=(m-n/k)/(k-1);
cout<<abs(n/k-p)<<endl;
}
else if ( (m-n/k)%(k-1)!=0 )
{
LL p=(m-n/k)/(k-1)+1;
cout<<abs(n/k-p)<<endl;
}
}
}
return 0;
}