codeforces A. Berland Poker

在這裏插入圖片描述

題目

題意:

伯蘭撲克遊戲有n副牌,其中m張是小丑。k個玩家玩這個遊戲(n能被k整除)。
在遊戲開始時,每個玩家從牌堆中取出nk\frac{n}{k}牌(因此每張牌只由一個玩家取出)。大小王數量最多的玩家就是贏家,他得到的點數等於x - y,其中x是贏家手中的大小王數量,y是所有其他玩家中最大的大小王數量。如果有兩個或更多的玩家有最大數量的小丑,他們都是贏家,他們得到0分。

思路:

我們讓其中一個人拿到最大的小丑數,然後剩餘的剩下的人均分,找均分中的最大數量,最後相減就得出答案了。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
int xxxxxxxxx = 1;
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}
inline void debug(ll x) {cout << xxxxxxxxx++ << " " << x << endl;}
inline void debugs(string s) {cout << s << endl;}
int main() {
    int t, n, m, k;
    read(t);
    while (t--) {
        read(n), read(m), read(k);
        int x = n / k;
        int ans = min(x, m);
        int y = max(0, m - ans);
        k--;
        y = y / k + ((y % k) > 0);
        ans -= y;
        outi(ans);
        putchar('\n');
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章