大模拟,一开始写完只有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;
}