CSP 201609-3 炉石传说

大模拟,一开始写完只有70分,发现是英雄死了之后我忘了输出随从状态了。。。。

#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct Minion {
    int atk, hel;

    Minion(int a = 0, int b = 0) {
        atk = a;    hel = b;
    }
};

struct Hero {
    int hel;
    vector<Minion> minions;

    Hero() {
        hel = 30;
    }
    void summon(int no, int atk, int hel) {
        minions.insert(minions.begin() + no - 1, Minion(atk, hel));
    }
    void update() {
        for (vector<Minion>::iterator it = minions.begin(); it != minions.end(); it++) {
            if (it->hel <= 0) {
                minions.erase(it);
                it--;
            }
        }
    }
} hero[3]; // first:0   second:1

void update() {
    hero[0].update();
    hero[1].update();

    if (hero[0].hel <= 0) {
        cout << "-1" << endl;
        cout << hero[0].hel << endl << hero[0].minions.size() << " ";
        for (vector<Minion>::iterator i = hero[0].minions.begin(); i != hero[0].minions.end(); i++) {
            cout << i->hel << " ";
        }
        cout << endl;

        cout << hero[1].hel << endl << hero[1].minions.size() << " ";
        for (vector<Minion>::iterator i = hero[1].minions.begin(); i != hero[1].minions.end(); i++) {
            cout << i->hel << " ";
        }
        exit(0);
    }

    if (hero[1].hel <= 0) {
        cout << "1" << endl;
        cout << hero[0].hel << endl << hero[0].minions.size() << " ";
        for (vector<Minion>::iterator i = hero[0].minions.begin(); i != hero[0].minions.end(); i++) {
            cout << i->hel << " ";
        }
        cout << endl;

        cout << hero[1].hel << endl << hero[1].minions.size() << " ";
        for (vector<Minion>::iterator i = hero[1].minions.begin(); i != hero[1].minions.end(); i++) {
            cout << i->hel << " ";
        }
        exit(0);
    }
}

int now;

int main()
{
    int n;
    cin >> n;
    while (n--) {
        string str;
        cin >> str;

        if (str == "summon") {
            int a, b, c;
            cin >> a >> b >> c;
            hero[now].summon(a, b, c);
        }
        else if (str == "attack") {
            int x, y;
            cin >> x >> y;
            if (y) {
                vector<Minion>::iterator a = (hero[now].minions.begin() + x - 1);
                vector<Minion>::iterator b = (hero[!now].minions.begin() + y - 1);
                a->hel -= b->atk;
                b->hel -= a->atk;
                update();
            }
            else {
                vector<Minion>::iterator a = (hero[now].minions.begin() + x - 1);
                hero[!now].hel -= a->atk;
                update();
            }
        }
        else now = !now;
    }

    cout << "0" << endl;
    cout << hero[0].hel << endl << hero[0].minions.size() << " ";
    for (vector<Minion>::iterator i = hero[0].minions.begin(); i != hero[0].minions.end(); i++) {
        cout << i->hel << " ";
    }
    cout << endl;

    cout << hero[1].hel << endl << hero[1].minions.size() << " ";
    for (vector<Minion>::iterator i = hero[1].minions.begin(); i != hero[1].minions.end(); i++) {
        cout << i->hel << " ";
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值