A. Berland Poker

这篇博客介绍了一种名为Berland Poker的游戏,玩家根据手中的joker数量得分。文章给出了若干示例并解析了得分规则,然后提供了一个C++代码片段用于计算在给定条件下,玩家能获得的最大分数。主要涉及逻辑推理和数学优化问题。
摘要由CSDN通过智能技术生成

Problem - A - Codeforces

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.

Example

input

Copy

4
8 3 2
4 2 4
9 6 3
42 0 7

output

Copy

3
0
1
0

Note

Test cases of the example are described in the statement.

#include<iostream>
using namespace std;
int t,n,m,k;
int main()
{
    cin>>t;
   while(t--) {
        cin>>n>>m>>k;
    int aver=n/k;//平均每人几张
   if(m<=aver) cout<<m<<endl;//全给第一个人,其他人没有
   else
   {
      if(m>=aver*2+(k-2)*(aver-1))cout<<0<<endl;//这种情况所有人都拿满了小丑
      else //如果第一个人的牌全是小丑,那么剩下的小丑牌全平分
      {
          if((m-aver)%(k-1)==0)
          {
              cout<<aver-((m-aver)/(k-1))<<endl;//如果剩下的小丑都可以平分,比如3 2 2这种情况
          }//那就直接输出3-2;
          else
          {
               cout<<aver-((m-aver)/(k-1))-1<<endl;//不可以平分,那就必有一个多的,那就是3 2 1
          }//那就输出再-1;
      }
      
   }
        
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值