CCF-CSP题解 201609-3 炉石传说

↘锁芯ラ 提交于 2019-11-28 05:13:35

模拟。

注意随从的编号在\(summon\)\(attack\)随从死亡时都可能改变。

#include <bits/stdc++.h>

using namespace std;

struct tNode
{
    int attack;
    int health;
};

tNode aPlayer[8];
tNode bPlayer[8];
int aM = 0, bM = 0;

int aHealth = 30, bHealth = 30;

int main()
{
    int n;
    scanf("%d", &n);

    int player = 1;
    char op[30];
    while (n--)
    {
        scanf("%s", op);
        if (op[0] == 's')
        {
            int pos, attack, health;
            scanf("%d%d%d", &pos, &attack, &health);
            if (player == 1)
            {
                for (int i = aM + 1; i >= pos + 1; i--)
                    aPlayer[i] = aPlayer[i - 1];
                aPlayer[pos].attack = attack;
                aPlayer[pos].health = health;
                aM++;
            }
            else
            {
                for (int i = bM + 1; i >= pos + 1; i--)
                    bPlayer[i] = bPlayer[i - 1];
                bPlayer[pos].attack = attack;
                bPlayer[pos].health = health;
                bM++;
            }
        }
        else if (op[0] == 'a')
        {
            int attacker, defender;
            scanf("%d%d", &attacker, &defender);
            if (player == 1)
            {
                if (defender == 0)
                {
                    bHealth -= aPlayer[attacker].attack;
                }
                else
                {
                    aPlayer[attacker].health -= bPlayer[defender].attack;
                    bPlayer[defender].health -= aPlayer[attacker].attack;
                    if (aPlayer[attacker].health <= 0)
                    {
                        for (int i = attacker; i <= aM - 1; i++)
                            aPlayer[i] = aPlayer[i + 1];
                        aM--;
                    }
                    if (bPlayer[defender].health <= 0)
                    {
                        for (int i = defender; i <= bM - 1; i++)
                            bPlayer[i] = bPlayer[i + 1];
                        bM--;
                    }
                }
            }
            else
            {
                if (defender == 0)
                {
                    aHealth -= bPlayer[attacker].attack;
                }
                else
                {
                    aPlayer[defender].health -= bPlayer[attacker].attack;
                    bPlayer[attacker].health -= aPlayer[defender].attack;
                    if (aPlayer[defender].health <= 0)
                    {
                        for (int i = defender; i <= aM - 1; i++)
                            aPlayer[i] = aPlayer[i + 1];
                        aM--;
                    }
                    if (bPlayer[attacker].health <= 0)
                    {
                        for (int i = attacker; i <= bM - 1; i++)
                            bPlayer[i] = bPlayer[i + 1];
                        bM--;
                    }
                }
            }
        }
        else
        {
            player *= -1;
        }
    }

    if (aHealth <= 0 || bHealth <= 0)
        printf("%d\n", player);
    else
        printf("0\n");

    printf("%d\n", aHealth);
    printf("%d", aM);
    for (int i = 1; i <= aM; i++)
        printf(" %d", aPlayer[i].health);
    printf("\n");

    printf("%d\n", bHealth);
    printf("%d", bM);
    for (int i = 1; i <= bM; i++)
        printf(" %d", bPlayer[i].health);
    printf("\n");

    return 0;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!