部分分做法 0 分求调
查看原帖
部分分做法 0 分求调
549357
幸存者楼主2022/8/17 18:12

写的是没有锦囊牌的 10 分部分分,但是调了一下午还是 WA,第一个测试点第 3,4,5 行结尾少输出了若干个 K,但第 6 行结尾却多输出了若干个 K

注:用队列写的,所以可能不太好理解

代码:

#include <bits/stdc++.h>
using namespace std;
int n, m;
struct Node
{
    string s;
    queue<char> q;
    int cnt = 4, x = 0;
    bool f = false;
} a[20];
queue<char> q;
bool flag()
{
    bool f1 = false, f2 = false;
    for (int i = 1; i <= n; i++)
    {
        if (a[i].s == "MP" && a[i].cnt > 0) f1 = true;
        if (a[i].s == "FP" && a[i].cnt > 0) f2 = true;
    }
    return f1 && f2;
}
void get(queue<char> &Q, int x)
{
    for (int i = 1; i <= x; i++)
    {
        char c = q.front();
        if (q.size() > 1) q.pop();
        Q.push(c);
    }
}
void clear(queue<char> &Q)
{
    queue<char> Survivor;
    swap(Q, Survivor);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].s;
        for (int j = 1; j <= 4; j++)
        {
            char c;
            cin >> c;
            a[i].q.push(c);
        }
    }
    while (m--)
    {
        char c;
        cin >> c;
        q.push(c);
    }
    while (flag())
    {
        for (int i = 1; i <= n; i++)
        {
            if (a[i].cnt <= 0) continue;
            get(a[i].q, 2);
            int cnt = 0, x = a[i].q.size();
            for (int j = 1; j <= x; j++)
            {
                char c = a[i].q.front();
                a[i].q.pop();
                if (c == 'P' && cnt + a[i].cnt < 4) cnt++;
                else if (c == 'Z') a[i].f = true;
                else a[i].q.push(c);
            }
            a[i].cnt += cnt;
            int nxt = (i == n ? 1 : i + 1);
            if (a[nxt].cnt > 0 && ((a[i].s == "FP" && a[nxt].s == "MP") || (a[nxt].x == 1 && (((a[i].s == "MP" || a[i].s == "ZP") && a[nxt].s == "FP") || (a[i].s == "FP" && a[nxt].s == "ZP")))))
            {
                int cnt1 = 0, cnt2 = 0;
                x = a[i].q.size();
                for (int j = 1; j <= x; j++)
                {
                    char c = a[i].q.front();
                    a[i].q.pop();
                    a[i].q.push(c);
                    if (c == 'K') cnt1++;
                }
                x = a[nxt].q.size();
                for (int j = 1; j <= x; j++)
                {
                    char c = a[nxt].q.front();
                    a[nxt].q.pop();
                    a[nxt].q.push(c);
                    if (c == 'D') cnt2++;
                }
                if (a[i].f)
                {
                    if (cnt1 > cnt2)
                    {
                        cnt1 = cnt2;
                        x = a[i].q.size();
                        for (int j = 1; j <= x; j++)
                        {
                            char c = a[i].q.front();
                            a[i].q.pop();
                            if (c == 'K' && cnt1 > 0) cnt1--;
                            else a[i].q.push(c);
                        }
                        x = a[nxt].q.size();
                        for (int j = 1; j <= x; j++)
                        {
                            char c = a[nxt].q.front();
                            a[nxt].q.pop();
                            if (c != 'D') a[nxt].q.push(c);
                        }
                        a[nxt].cnt--;
                        if (a[nxt].cnt == 0)
                        {
                            x = a[nxt].q.size();
                            for (int j = 1; j <= x; j++)
                            {
                                char c = a[nxt].q.front();
                                a[nxt].q.pop();
                                if (c == 'P' && a[nxt].cnt == 0) a[nxt].cnt++;
                                a[nxt].q.push(c);
                            }
                            if (a[nxt].cnt == 0)
                            {
                                if (!flag()) break;
                                if (a[i].s == "MP" && a[nxt].s == "ZP")
                                {
                                    clear(a[i].q);
                                    a[i].f = false;
                                }
                                else if (a[nxt].s == "FP") get(a[i].q, 3);
                            }
                        }
                    }
                    else
                    {
                        cnt2 = cnt1;
                        x = a[i].q.size();
                        for (int j = 1; j <= x; j++)
                        {
                            char c = a[i].q.front();
                            a[i].q.pop();
                            if (c != 'K') a[i].q.push(c);
                        }
                        x = a[nxt].q.size();
                        for (int j = 1; j <= x; j++)
                        {
                            char c = a[nxt].q.front();
                            a[nxt].q.pop();
                            if (c == 'D' && cnt2 > 0) cnt2--;
                            else a[nxt].q.push(c);
                        }
                    }
                }
                else
                {
                    if (cnt1 > 0 && cnt2 > 0)
                    {
                        cnt1 = cnt2 = 1;
                        x = a[i].q.size();
                        for (int j = 1; j <= x; j++)
                        {
                            char c = a[i].q.front();
                            a[i].q.pop();
                            if (c == 'K' && cnt1 > 0) cnt1--;
                            else a[i].q.push(c);
                        }
                        x = a[nxt].q.size();
                        for (int j = 1; j <= x; j++)
                        {
                            char c = a[nxt].q.front();
                            a[nxt].q.pop();
                            if (c == 'D' && cnt2 > 0) cnt2--;
                            else a[nxt].q.push(c);
                        }
                    }
                    else if (cnt1 > 0)
                    {
                        cnt1 = 1;
                        x = a[i].q.size();
                        for (int j = 1; j <= x; j++)
                        {
                            char c = a[i].q.front();
                            a[i].q.pop();
                            if (c == 'K' && cnt1 > 0) cnt1--;
                            else a[i].q.push(c);
                        }
                        a[nxt].cnt--;
                        if (a[nxt].cnt == 0)
                        {
                            x = a[nxt].q.size();
                            for (int j = 1; j <= x; j++)
                            {
                                char c = a[nxt].q.front();
                                a[nxt].q.pop();
                                if (c == 'P' && a[nxt].cnt == 0) a[nxt].cnt++;
                                a[nxt].q.push(c);
                            }
                            if (a[nxt].cnt == 0)
                            {
                                if (!flag()) break;
                                if (a[i].s == "MP" && a[nxt].s == "ZP")
                                {
                                    clear(a[i].q);
                                    a[i].f = false;
                                }
                                else if (a[nxt].s == "FP") get(a[i].q, 3);
                            }
                        }
                    }
                }
                a[i].x = 1;
            }
        }
    }
    bool f1 = false, f2 = false;
    for (int i = 1; i <= n; i++)
    {
        if (a[i].s == "MP" && a[i].cnt > 0) f1 = true;
        if (a[i].s == "FP" && a[i].cnt > 0) f2 = true;
    }
    if (f1) cout << "MP" << endl;
    else cout << "FP" << endl;
    for (int i = 1; i <= n; i++)
    {
        if (a[i].cnt <= 0) cout << "DEAD";
        else while (!a[i].q.empty())
        {
            cout << a[i].q.front() << " ";
            a[i].q.pop();
        }
        cout << endl;
    }
    return 0;
}
2022/8/17 18:12
加载中...