一句话,大模拟,对着题意敲就完了。

干就完了,奥利给!

正正好好 618 行~

// 10665 Problem G:【省选基础 模拟】魔兽世界终极版
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
using namespace std;
const string HEADNAME[2] = {"red", "blue"}, CREATE[2][5] = {{"iceman", "lion", "wolf", "ninja", "dragon"}, {"lion", "dragon", "ninja", "iceman", "wolf"}}, WEAPONNAME[3] = {"sword", "bomb", "arrow"};
struct Weapon
{
    int atk;
    Weapon(int type, int _atk)
    {
        if (!type)
            atk = _atk * 2 / 10;
        else if (type == 1)
            atk = 10000;
        else if (type == 2)
            atk = 3;
        return;
    }
};
struct Command
{
    int warrior, location, element, id;
    string type;
    Command() {}
    Command(string);
} head[2];
struct Warrior
{
    int life, id, force, step, loyalty;
    double morale;
    string type, mast;
    Weapon *weapons[3];
    Warrior(string, int, string, double);
    string identity() { return mast + ' ' + type + ' ' + to_string(id); }
    int useSword(bool mode)
    {
        if (weapons[0])
        {
            if (!mode)
                return weapons[0]->atk;
            else
            {
                weapons[0]->atk = weapons[0]->atk * 8 / 10;
                if (!weapons[0]->atk)
                    weapons[0] = nullptr;
                return 0;
            }
        }
        return 0;
    }
    int sumAtk(bool defense)
    {
        if (defense)
            return force / 2 + useSword(false);
        return force + useSword(false);
    }
    void rob(Warrior *one)
    {
        for (int i = 0; i < 3; i++)
            if (!weapons[i])
                weapons[i] = one->weapons[i];
        return;
    }
    string outWeapon()
    {
        int sum = 0, cnt = 0;
        bool bb[3];
        string res = "";
        for (int i = 0; i < 3; i++)
        {
            bb[i] = weapons[i];
            sum += bb[i];
        }
        for (int i = 2; ~i; i--)
        {
            if (weapons[i])
            {
                res += WEAPONNAME[i];
                if (WEAPONNAME[i] != "bomb")
                    res += '(' + to_string(weapons[i]->atk) + ')';
                if (++cnt != sum)
                    res += ',';
            }
        }
        return res;
    }
} * cities[25][2], *redReached, *blueReached;
struct City
{
    int soldiers, winTime[2], element;
} allCity[25];
int cases, m, n, r, k, t, hour, minute, _hour, _minute, arrowWin[25], headTaken[2], flag[25], winner[25], giveReward[25], firstFlag[25];
bool endFlag;
map<string, int> hp, atk;
Command::Command(string _type)
{
    type = _type;
    if (type == "red")
    {
        location = 0;
        id = 0;
    }
    else
    {
        location = n + 1;
        id = 1;
    }
    element = m;
    warrior = 0;
    return;
}
Warrior::Warrior(string _mast, int _id, string _type, double _element)
{
    Weapon *w1, *w2;
    mast = _mast;
    id = _id;
    type = _type;
    step = loyalty = 0;
    morale = 0.0;
    life = hp[type];
    force = atk[type];
    for (int i = 0; i < 3; i++)
        weapons[i] = nullptr;
    w1 = new Weapon(id % 3, force);
    w2 = new Weapon((id + 1) % 3, force);
    if (w1->atk == 0)
        w1 = nullptr;
    if (w2->atk == 0)
        w2 = nullptr;
    if (type == "dragon")
    {
        weapons[id % 3] = w1;
        morale = _element / (hp[type] * 1.0);
    }
    else if (type == "ninja")
    {
        weapons[id % 3] = w1;
        weapons[(id + 1) % 3] = w2;
    }
    else if (type == "lion")
        loyalty = _element;
    else if (type == "iceman")
        weapons[id % 3] = w1;
    return;
}
void clear()
{
    hour = minute = 0;
    endFlag = false;
    _hour = t / 60;
    _minute = t % 60;
    head[0] = Command("red");
    head[1] = Command("blue");
    for (int i = 0; i <= n + 1; i++)
    {
        cities[i][0] = cities[i][1] = nullptr;
        allCity[i].element = allCity[i].soldiers = allCity[i].winTime[0] = allCity[i].winTime[1] = 0;
        if (i % 2 == 0)
            flag[i] = 1;
        else
            flag[i] = 0;
    }
    memset(firstFlag, 0, sizeof(firstFlag));
    memset(winner, 0, sizeof(winner));
    memset(giveReward, 0, sizeof(giveReward));
    memset(arrowWin, 0, sizeof(arrowWin));
    blueReached = redReached = nullptr;
    headTaken[0] = headTaken[1] = 0;
    return;
}
void init()
{
    scanf("%d%d%d%d%d", &m, &n, &r, &k, &t);
    scanf("%d%d%d%d%d", &hp["dragon"], &hp["ninja"], &hp["iceman"], &hp["lion"], &hp["wolf"]);
    scanf("%d%d%d%d%d", &atk["dragon"], &atk["ninja"], &atk["iceman"], &atk["lion"], &atk["wolf"]);
    return;
}
void createWarriors()
{
    string wtype;
    Warrior *newone;
    for (int i = 0; i < 2; i++)
    {
        wtype = CREATE[i][(head[i].warrior % 5)];
        if (hp[wtype] <= head[i].element)
        {
            head[i].warrior++;
            head[i].element -= hp[wtype];
            newone = new Warrior(HEADNAME[i], head[i].warrior, wtype, head[i].element);
            cities[head[i].location][head[i].id] = newone;
            printf("%03d:00 %s %s %d born\n", hour, head[i].type.c_str(), wtype.c_str(), newone->id);
            if (wtype == "dragon")
                printf("Its morale is %.2lf\n", newone->morale);
            if (wtype == "lion")
                printf("Its loyalty is %d\n", newone->loyalty);
        }
    }
    return;
}
void lionEscape()
{
    for (int i = 0; i <= n + 1; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            if (cities[i][j] && cities[i][j]->type == "lion" && cities[i][j]->loyalty <= 0)
            {
                printf("%03d:05 %s ran away\n", hour, cities[i][j]->identity().c_str());
                cities[i][j] = nullptr;
            }
        }
    }
    return;
}
void marching()
{
    Warrior *temp[25][2];
    for (int i = 0; i <= n + 1; i++)
    {
        temp[i][0] = cities[i][0];
        temp[i][1] = cities[i][1];
    }
    for (int i = 0; i <= n + 1; i++)
        cities[i][0] = cities[i][1] = nullptr;
    for (int i = 0; i <= n + 1; i++)
    {
        if (temp[i][0])
        {
            cities[i + 1][0] = temp[i][0];
            temp[i][0]->step++;
            if (temp[i][0]->type == "iceman" && temp[i][0]->step % 2 == 0)
            {
                temp[i][0]->force += 20;
                temp[i][0]->life -= 9;
                if (temp[i][0]->life <= 0)
                    temp[i][0]->life = 1;
            }
        }
        if (temp[i][1])
        {
            cities[i - 1][1] = temp[i][1];
            temp[i][1]->step++;
            if (temp[i][1]->type == "iceman" && temp[i][1]->step % 2 == 0)
            {
                temp[i][1]->force += 20;
                temp[i][1]->life -= 9;
                if (temp[i][1]->life <= 0)
                    temp[i][1]->life = 1;
            }
        }
    }
    for (int i = 0; i <= n + 1; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            if (cities[i][j])
            {
                if (i == 0)
                {
                    printf("%03d:10 %s reached red headquarter with %d elements and force %d\n", hour, cities[i][j]->identity().c_str(), cities[i][j]->life, cities[i][j]->force);
                    headTaken[0]++;
                    if (headTaken[0] == 2)
                    {
                        printf("%03d:10 red headquarter was taken\n", hour);
                        endFlag = true;
                    }
                    redReached = cities[i][j];
                }
                else if (i == n + 1)
                {
                    printf("%03d:10 %s reached blue headquarter with %d elements and force %d\n", hour, cities[i][j]->identity().c_str(), cities[i][j]->life, cities[i][j]->force);
                    headTaken[1]++;
                    if (headTaken[1] == 2)
                    {
                        printf("%03d:10 blue headquarter was taken\n", hour);
                        endFlag = true;
                    }
                    blueReached = cities[i][j];
                }
                else
                    printf("%03d:10 %s marched to city %d with %d elements and force %d\n", hour, cities[i][j]->identity().c_str(), i, cities[i][j]->life, cities[i][j]->force);
            }
        }
    }
}
void elementProduce()
{
    for (int i = 1; i <= n; i++)
    {
        allCity[i].element += 10;
    }
    return;
}
void getElement()
{
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            if (cities[i][j] && !cities[i][j ^ 1] && allCity[i].element)
            {
                printf("%03d:30 %s earned %d elements for his headquarter\n", hour, cities[i][j]->identity().c_str(), allCity[i].element);
                head[j].element += allCity[i].element;
                allCity[i].element = 0;
            }
        }
    }
    return;
}
void arrowReleased()
{
    for (int i = 1; i <= n; i++)
    {
        if (cities[i][0] && cities[i + 1][1] && cities[i][0]->weapons[2])
        {
            cities[i + 1][1]->life -= r;
            cities[i][0]->weapons[2]->atk--;
            if (!cities[i][0]->weapons[2]->atk)
                cities[i][0]->weapons[2] = nullptr;
            if (cities[i + 1][1]->life <= 0)
            {
                printf("%03d:35 %s shot and killed %s\n", hour, cities[i][0]->identity().c_str(), cities[i + 1][1]->identity().c_str());
                arrowWin[i + 1] = 1;
            }
            else
                printf("%03d:35 %s shot\n", hour, cities[i][0]->identity().c_str());
        }
        if (cities[i][1] && cities[i - 1][0] && cities[i][1]->weapons[2])
        {
            cities[i - 1][0]->life -= r;
            cities[i][1]->weapons[2]->atk--;
            if (!cities[i][1]->weapons[2]->atk)
                cities[i][1]->weapons[2] = nullptr;
            if (cities[i - 1][0]->life <= 0)
            {
                printf("%03d:35 %s shot and killed %s\n", hour, cities[i][1]->identity().c_str(), cities[i - 1][0]->identity().c_str());
                arrowWin[i - 1] = 1;
            }
            else
                printf("%03d:35 %s shot\n", hour, cities[i][1]->identity().c_str());
        }
    }
    return;
}
void bombUsed()
{
    for (int i = 1, j; i <= n; i++)
    {
        j = flag[i];
        if (cities[i][j] && cities[i][j ^ 1] && cities[i][j]->life > 0 && cities[i][j ^ 1]->life > 0)
        {
            if (cities[i][j ^ 1]->type != "ninja" && cities[i][j]->weapons[1] && cities[i][j ^ 1]->life > cities[i][j]->sumAtk(false) && cities[i][j ^ 1]->sumAtk(true) >= (cities[i][j]->life))
            {
                printf("%03d:38 %s used a bomb and killed %s\n", hour, cities[i][j]->identity().c_str(), cities[i][j ^ 1]->identity().c_str());
                cities[i][j] = cities[i][j ^ 1] = nullptr;
            }
            else if (cities[i][j ^ 1]->weapons[1] && cities[i][j]->sumAtk(false) >= cities[i][j ^ 1]->life)
            {
                printf("%03d:38 %s used a bomb and killed %s\n", hour, cities[i][j ^ 1]->identity().c_str(), cities[i][j]->identity().c_str());
                cities[i][j] = cities[i][j ^ 1] = nullptr;
            }
        }
    }
    return;
}
void judge()
{
    memset(giveReward, 0, sizeof(int) * 25);
    for (int i = 1; i <= n; i++)
    {
        if (cities[i][0] && cities[i][1])
        {
            if (cities[i][flag[i]]->sumAtk(0) >= cities[i][flag[i] ^ 1]->life)
                winner[i] = flag[i];
            else if (cities[i][flag[i] ^ 1]->type != "ninja" && cities[i][flag[i] ^ 1]->sumAtk(1) >= cities[i][flag[i]]->life)
                winner[i] = flag[i] ^ 1;
        }
        if (arrowWin[i])
        {
            for (int j = 0; j < 2; j++)
                if (cities[i][j])
                    winner[i] = j;
        }
    }
    int r_reward = head[0].element / 8, b_reward = head[1].element / 8;
    for (int i = 1; i <= n; i++)
    {
        if (winner[i] == 0)
        {
            if (r_reward)
            {
                giveReward[i] = 1;
                r_reward--;
            }
        }
        if (winner[n + 1 - i] == 1)
        {
            if (b_reward)
            {
                giveReward[i] = 1;
                b_reward--;
            }
        }
    }
}
void battle()
{
    judge();
    for (int i = 1; i <= n; i++)
    {
        if (arrowWin[i])
        {
            for (int j = 0; j < 2; j++)
            {
                if (cities[i][j] && cities[i][j ^ 1] && cities[i][j ^ 1]->life <= 0 && cities[i][j]->life <= 0)
                {
                    cities[i][j] = nullptr;
                    cities[i][j ^ 1] = nullptr;
                }
                else if (cities[i][j] && cities[i][j ^ 1] && cities[i][j ^ 1]->life <= 0)
                {
                    if (cities[i][j]->type == "wolf")
                        cities[i][j]->rob(cities[i][j ^ 1]);
                    cities[i][j ^ 1] = nullptr;
                }
                else if (cities[i][j] && !cities[i][j ^ 1])
                    cities[i][j] = nullptr;
            }
        }
        if (cities[i][0] && cities[i][1])
        {
            arrowWin[i] = 1;
            {
                int hp_atk = cities[i][flag[i]]->life, hp_rcp = cities[i][flag[i] ^ 1]->life;
                cities[i][flag[i] ^ 1]->life -= cities[i][flag[i]]->sumAtk(0);
                cities[i][flag[i]]->useSword(1);
                printf("%03d:40 %s attacked %s in city %d with %d elements and force %d\n", hour, cities[i][flag[i]]->identity().c_str(), cities[i][flag[i] ^ 1]->identity().c_str(), i, cities[i][flag[i]]->life, cities[i][flag[i]]->force);
                if (cities[i][flag[i] ^ 1]->life > 0 && cities[i][flag[i] ^ 1]->type != "ninja")
                {
                    cities[i][flag[i]]->life -= cities[i][flag[i] ^ 1]->sumAtk(1);
                    cities[i][flag[i] ^ 1]->useSword(1);
                    printf("%03d:40 %s fought back against %s in city %d\n", hour, cities[i][flag[i] ^ 1]->identity().c_str(), cities[i][flag[i]]->identity().c_str(), i);
                    if (cities[i][flag[i]]->life <= 0)
                    {
                        printf("%03d:40 %s was killed in city %d\n", hour, cities[i][flag[i]]->identity().c_str(), i);
                        if (cities[i][flag[i] ^ 1]->type == "wolf")
                            cities[i][flag[i] ^ 1]->rob(cities[i][flag[i]]);
                        if (cities[i][flag[i]]->type == "lion")
                            cities[i][flag[i] ^ 1]->life += hp_atk;
                        cities[i][flag[i]] = nullptr;
                    }
                }
                else if (cities[i][flag[i] ^ 1]->life <= 0)
                {
                    printf("%03d:40 %s was killed in city %d\n", hour, cities[i][flag[i] ^ 1]->identity().c_str(), i);
                    if (cities[i][flag[i]]->type == "wolf")
                        cities[i][flag[i]]->rob(cities[i][flag[i] ^ 1]);
                    if (cities[i][flag[i] ^ 1]->type == "lion")
                        cities[i][flag[i]]->life += hp_rcp;
                    cities[i][flag[i] ^ 1] = nullptr;
                }
            }
            if (cities[i][0] && cities[i][1])
                allCity[i].winTime[0] = allCity[i].winTime[1] = 0;
        }
        if (arrowWin[i])
        {
            for (int j = 0; j < 2; j++)
            {
                if (cities[i][j])
                {
                    if (cities[i][j]->type == "dragon" && !cities[i][j ^ 1])
                        cities[i][j]->morale += 0.2;
                    if (cities[i][j]->type == "dragon" && cities[i][j ^ 1])
                        cities[i][j]->morale -= 0.2;
                    if (j == flag[i] && cities[i][j]->type == "dragon" && cities[i][j]->morale > 0.8)
                        printf("%03d:40 %s yelled in city %d\n", hour, cities[i][j]->identity().c_str(), i);
                    if (cities[i][j ^ 1] && cities[i][j]->type == "lion")
                        cities[i][j]->loyalty -= k;
                    if (!cities[i][j ^ 1])
                    {
                        if (giveReward)
                        {
                            cities[i][j]->life += 8;
                            head[j].element -= 8;
                        }
                        printf("%03d:40 %s earned %d elements for his headquarter\n", hour, cities[i][j]->identity().c_str(), allCity[i].element);
                        head[j].element += allCity[i].element;
                        allCity[i].element = 0;
                        allCity[i].winTime[j]++;
                        allCity[i].winTime[j ^ 1] = 0;
                        if (allCity[i].winTime[j] == 2 && flag[i] != j || firstFlag[i] == 0)
                        {
                            firstFlag[i] = 1;
                            flag[i] = j;
                            printf("%03d:40 %s flag raised in city %d\n", hour, head[j].type.c_str(), i);
                        }
                    }
                }
            }
        }
    }
    return;
}
void reportElement()
{
    printf("%03d:%02d %d elements in red headquarter\n", hour, minute, head[0].element);
    printf("%03d:%02d %d elements in blue headquarter\n", hour, minute, head[1].element);
    return;
}
void reportWarrior()
{
    for (int i = 0; i <= n; i++)
    {
        if (cities[i][0])
        {
            if (!cities[i][0]->weapons[0] && !cities[i][0]->weapons[1] && !cities[i][0]->weapons[2])
                printf("%03d:55 %s has no weapon\n", hour, cities[i][0]->identity().c_str());
            else
                printf("%03d:55 %s has %s\n", hour, cities[i][0]->identity().c_str(), cities[i][0]->outWeapon().c_str());
        }
    }
    if (blueReached)
    {
        if (!blueReached->weapons[0] && !blueReached->weapons[1] && !blueReached->weapons[2])
            printf("%03d:55 %s has no weapon\n", hour, blueReached->identity().c_str());
        else
            printf("%03d:55 %s has %s\n", hour, blueReached->identity().c_str(), blueReached->outWeapon().c_str());
    }
    if (redReached)
    {
        if (!redReached->weapons[0] && !redReached->weapons[1] && !redReached->weapons[2])
            printf("%03d:55 %s has no weapon\n", hour, redReached->identity().c_str());
        else
            printf("%03d:55 %s has %s\n", hour, redReached->identity().c_str(), redReached->outWeapon().c_str());
    }
    for (int i = 1; i <= n + 1; i++)
    {
        if (cities[i][1])
        {
            if (!cities[i][1]->weapons[0] && !cities[i][1]->weapons[1] && !cities[i][1]->weapons[2])
                printf("%03d:55 %s has no weapon\n", hour, cities[i][1]->identity().c_str());
            else
                printf("%03d:55 %s has %s\n", hour, cities[i][1]->identity().c_str(), cities[i][1]->outWeapon().c_str());
        }
    }
    return;
}

int main()
{
    scanf("%d", &cases);
    for (int c = 1; c <= cases; c++)
    {
        init();
        clear();
        printf("Case %d:\n", c);
        while (true)
        {
            minute = 0;
            if (hour == _hour && minute > _minute)
                break;
            createWarriors();
            minute = 5;
            if (hour == _hour && minute > _minute)
                break;
            lionEscape();
            minute = 10;
            if (hour == _hour && minute > _minute)
                break;
            marching();
            if (endFlag)
                break;
            minute = 20;
            if (hour == _hour && minute > _minute)
                break;
            elementProduce();
            minute = 30;
            if (hour == _hour && minute > _minute)
                break;
            getElement();
            minute = 35;
            if (hour == _hour && minute > _minute)
                break;
            arrowReleased();
            minute = 38;
            if (hour == _hour && minute > _minute)
                break;
            bombUsed();
            minute = 40;
            if (hour == _hour && minute > _minute)
                break;
            for (int i = 1; i <= n; i++)
                winner[i] = -1;
            battle();
            memset(arrowWin, 0, sizeof(arrowWin));
            minute = 50;
            if (hour == _hour && minute > _minute)
                break;
            reportElement();
            minute = 55;
            if (hour == _hour && minute > _minute)
                break;
            reportWarrior();
            hour++;
        }
    }
    return 0;
}
/*
 * Source: AcCoders-省选基础32—模拟搜索
 * URL: http://www.accoders.com/problem.php?cid=2107&pid=6
 * Command: -std=c++23 -Wall -fno-ms-extensions
 * Date: 2022.10.18
 */

原文地址:http://www.cnblogs.com/2020gyk080/p/16805003.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性