CSP 201609-3炉石传说

CSP 201609-3炉石传说

问题描述

在这里插入图片描述

输入格式

在这里插入图片描述

输出格式

在这里插入图片描述

样例输入

8
summon 1 3 6
summon 2 4 2
end
summon 1 4 5
summon 1 2 1
attack 1 2
end
attack 1 1

样例输出

0
30
1 2
30
1 2

评测用例规模与约定

在这里插入图片描述

题意:
模拟“炉石传说”的游戏过程。

分析:
使用一个struct类型来表示人物,里面包括生命值、攻击值和标记是否已经有人物了。对每个玩家都有一个数组来存储英雄和随从的信息。
召唤随从时,要看召唤的位置是否已经有了随从,如果有了的,要把从这个位置往后,都后移一位,如果没有,只要直接放入相应的位置即可。
攻击时,改变对应位置的生命值就可。但是如果英雄被杀死,就直接结束这次攻击,如果某个随从死了,要改变它后面的随从的位置,都提前一位。
end操作时,改变当前处理的玩家即可,可以用一个变量now,来控制。

代码如下:

#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];

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、付费专栏及课程。

余额充值