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;
}