201609-3 炉石传说

炉石传说

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

解题思路:
定义一个node里面存放着生命健康值和攻击值,在擦汗如的时候,注意所有右边的编号都会+1,当死去的时候,所有右边的随从编号都-1,定义两个vector分别表示两个玩家的随从,0,1;然后判断他的语句,
①summon,召唤随从就插入
②attack 分别-对方的攻击值,然后判断他的健康值是否>0,如果已经死掉,就删除
③end 换成另一个玩家。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include<functional>
#define MAXN 30005
#define inf 1e9

using namespace std;

struct node{
	int health;
	int attack;
	node(int h, int a){
		this->health=h;
		this->attack=a;
	}
};

vector<node> player[2];

int main()
{
	int n,a,b,c;
	string op;
	cin >> n;
	int flag = 0;
	player[0].push_back(node(30,0));
	player[1].push_back(node(30,0));
	while(n--)
	{
		cin >> op;
		if(op == "summon")
		{
			cin >> a >> b >> c;
			player[flag].insert(player[flag].begin()+a,node(c,b));
		}
		else if(op == "attack")
		{
			cin >> a >> b;
			player[flag][a].health -= player[!flag][b].attack;
			player[!flag][b].health -= player[flag][a].attack;
            if(player[flag][a].health <= 0 && a != 0) 
			{
                player[flag].erase(player[flag].begin()+a);
            }
            if(player[!flag][b].health <= 0 && b != 0) 
			{
                player[!flag].erase(player[!flag].begin()+b);
            }
		}
		else if(op == "end") 
		{
            flag = !flag;
        }
	}
	if(player[0][0].health > 0 && player[1][0].health > 0)
	{
		cout << 0 << endl;
	}
	else if(player[0][0].health > 0) 
	{
		cout << 1 << endl;
	}
	else if(player[1][0].health > 0)
	{
		cout << -1 << endl;
    } 
    cout << player[0][0].health << endl;
    cout << player[0].size()-1 << " ";
    for(int i = 1; i < player[0].size(); i++) 
	{
        cout << player[0][i].health << " ";
    }
    cout << endl;
    cout << player[1][0].health << endl;
    cout << player[1].size()-1 << " ";
    for(int i = 1; i < player[1].size(); i++) 
	{
        cout << player[1][i].health << " ";
    }
    cout << endl;
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值