炉石传说
解题思路:
定义一个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;
}