ACM-ICPC 2018 Nanjing Division Network Preliminaries C. GDY

题解

题大意 n人m cards starting from the 1st, each person takes 5 cards directly in order to ensure that each person will have a card but does not guarantee The last person has enough cards Similar to the playing card size relationship 2>1>13>12>...>4>3 The smallest card from 1 can only be played one at a time. Each time the card is played, it can only be one level higher than the previous one. The last card is not 2 current players and 2 can be 2 or else If there is no card in all rounds, then everyone who draws a card from the last player and then the player who makes the last card will have a minimum card.

Too difficult to understand the amount of data is very small direct violence simulation

AC code

#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; //conversion 0~12
            if (i < n * 5)
                st[i / 5].insert(t); // label from 0 to the convenience of calculation 
            else
                q.push(t);
        }
        int now = 0, last = *st[0].begin(), run = 1; // first out a card | ||st[
        st[0].erase(st[0].begin());
        for (int i = 1; run; i = (i + 1) % n)
        {
            if (i == now) //Nobody can play {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()) // Find big 1now = i, last = *it, st[i].erase(it); else if (last != 12) //When the previous card is not 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; //reversest[i].clear();printf("%lld\n", s);
            }
        }
    }

    return 0;
}