AcWing 3234. 炉石传说
原题链接
中等
作者:
KeChang
,
2023-11-21 14:45:22
,
所有人可见
,
阅读 45
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int n;
bool player;
string line;
typedef struct {
int h = 0, a = 0;
}fl;
vector <fl> fls[2];
void summon(int p, int a, int h) {
fl tar = {h,a};
if(p > fls[player].size()) fls[player].push_back(tar);
else {
vector <fl> temp;
int i = 0;
for(; i < p; ++i) temp.push_back(fls[player][i]);
temp.push_back(tar);
for(; i < fls[player].size(); ++i) temp.push_back(fls[player][i]);
fls[player] = temp;
}
}
void attack(int a, int b) {
fls[player][a].h -= fls[!player][b].a;
fls[!player][b].h -= fls[player][a].a;
if(a && fls[player][a].h <= 0) fls[player].erase(fls[player].begin() + a);
if(b && fls[!player][b].h <= 0) fls[!player].erase(fls[!player].begin() + b);
}
void getStatus(int p) {
cout << fls[p][0].h << '\n' << fls[p].size() - 1 << ' ';
for(int i = 1; i < fls[p].size(); ++i) cout << fls[p][i].h << ' ';
cout << '\n';
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
fls[0].push_back({30,0});
fls[1].push_back({30,0});
cin >> n;
cin.ignore();
while(n--) {
if(fls[0][0].h <= 0 || fls[1][0].h <= 0) continue;
getline(cin, line);
stringstream sstr(line);
sstr >> line;
if(line == "summon") {
int p, a, h;
sstr >> p >> a >> h;
summon(p, a, h);
}
else if(line == "attack") {
int a, d;
sstr >> a >> d;
attack(a, d);
}
else if (line == "end") {
player = !player;
}
}
if(fls[1][0].h <= 0) cout << 1 << '\n';
else if (fls[0][0].h <= 0) cout << -1 << '\n';
else cout << 0 << '\n';
getStatus(0);
getStatus(1);
return 0;
}