ACM-ICPC 2018 南京赛区网络预赛 C. GDY

题解

题目大意 n个人m张牌 从1号开始按顺序每人直接取5张牌 题目保证每人都会有牌但不保证最后一个人的牌够5张
类似于扑克牌大小关系2>1>13>12>…>4>3 从1开始出最小的牌 每次只能出一张 每次出牌只能出比上一个人大一级的如果没有 并且上一张牌不是2当前出牌人还有2则可以出2 否则就过
如果一轮下来 所有人都没有牌可以出 则从最后出牌的人开始每人取一张牌 然后最后出牌的人出一张最小的牌

过的人很少好像是因为题目太难懂 数据量很小 直接暴力模拟

AC代码

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 210;
multiset<int> st[MAXN];

int main()
{
#ifdef LOCAL
    freopen("C:/input.txt", "r", stdin);
#endif
    int T;
    cin >> T;
    for (int ti = 1; ti <= T; ti++)
    {
        int n, m;
        cin >> n >> m;
        queue<int> q;
        for (int i = 0; i < m; i++)
        {
            int t;
            scanf("%d", &t);
            t = (t + 10) % 13; //转换0~12
            if (i < n * 5)
                st[i / 5].insert(t); //标号从0开始 方便计算
            else
                q.push(t);
        }
        int now = 0, last = *st[0].begin(), run = 1; //先出一张牌
        st[0].erase(st[0].begin());
        for (int i = 1; run; i = (i + 1) % n)
        {
            if (i == now) //没人能出牌
            {
                for (int j = 0; j < n && !q.empty(); j++)
                    st[(i + j) % n].insert(q.front()), q.pop();
                last = *st[i].begin();
                st[i].erase(st[i].begin());
            }
            else
            {
                multiset<int>::iterator it = st[i].find(last + 1);
                if (it != st[i].end()) //找到大1
                    now = i, last = *it, st[i].erase(it);
                else if (last != 12) //上一张牌不为2的情况下 
                {
                    it = st[i].find(12); //2
                    if (it != st[i].end())
                        now = i, last = *it, st[i].erase(it);
                }
            }
            if (st[i].empty())
                run = 0;
        }
        printf("Case #%d:\n", ti);
        for (int i = 0; i < n; i++)
        {
            if (st[i].empty())
                printf("Winner\n");
            else
            {
                ll s = 0;
                for (auto it : st[i])
                    s += (it + 2) % 13 + 1; //逆转
                st[i].clear();
                printf("%lld\n", s);
            }
        }
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/CaprYang/article/details/82707468
今日推荐