A. BERLAND POKER

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:

  • n=8n=8, m=3m=3, k=2k=2. If one player gets 33 jokers and 11 plain card, and another player gets 00 jokers and 44 plain cards, then the first player is the winner and gets 3−0=33−0=3 points;
  • n=4n=4, m=2m=2, k=4k=4. Two players get plain cards, and the other two players get jokers, so both of them are winners and get 00 points;
  • n=9n=9, m=6m=6, k=3k=3. If the first player gets 33 jokers, the second player gets 11 joker and 22 plain cards, and the third player gets 22 jokers and 11 plain card, then the first player is the winner, and he gets 3−2=13−2=1 point;
  • n=42n=42, m=0m=0, k=7k=7. Since there are no jokers, everyone gets 00 jokers, everyone is a winner, and everyone gets 00 points.

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;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/106447536