题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
include[HTML_REMOVED]
using namespace std;
using gg = long long;
typedef struct suicong{
gg health;
gg attack;
}suicong;
typedef struct wanjia{
gg yx_health;
vector[HTML_REMOVED]v;
}wanjia;
int main(){
int n; cin >> n; getchar();
wanjia stu[2]; stu[0].yx_health = 30; stu[1].yx_health = 30;
int ans = 0,fuck = 0;
for(int i = 0;i < n;i){
string str;
getline(cin,str);
if(str == “end”){
ans = (ans + 1) % 2;
continue;
}
string s = str.substr(0,6);
if(s == “summon”){ //布置随从
int position = str[7] - ‘0’;
int fff = 0;
for(auto it = str.begin() + 9;it!=str.end();it){
if(it == ‘ ‘) break;
fff;
}
int _attack = stoi(str.substr(9,fff));
int fff1 = 0;
for(auto it = str.begin() + 9 + fff + 1;it!=str.end();it){
if(it == ‘ ‘) break;
fff1;
}
int _health = stoi(str.substr(10 + fff,fff1));
auto it = stu[ans].v.begin();
suicong temp; temp.health = _health; temp.attack = _attack;
stu[ans].v.insert(it + position - 1,temp);
}
else{ //随从攻击
int position1 = str[7] - ‘0’,position2 = str[9] - ‘0’;
auto it1 = stu[ans].v.begin() + position1 - 1;
if(position2 == 0){
stu[(ans + 1) % 2].yx_health -= it1->attack;
if(stu[(ans + 1) % 2].yx_health <= 0){
fuck = 1;
break;
}
continue;
}
auto it2 = stu[(ans + 1) % 2].v.begin() + position2 - 1;
it1->health -= it2->attack;
it2->health -= it1->attack;
if(it1->health <= 0)
stu[ans].v.erase(it1);
if(it2->health <= 0)
stu[(ans + 1) % 2].v.erase(it2);
}
}
if(stu[0].yx_health > 0 && stu[1].yx_health > 0) cout << ‘0’;
else if(stu[0].yx_health > 0) cout << ‘1’;
else cout << “-1”; //注意,‘-1’输出的不是-1!!!
cout << endl;
cout << stu[0].yx_health << endl;
cout << stu[0].v.size();
for(int i = 0;i < stu[0].v.size();i)
cout << ‘ ‘ << stu[0].v[i].health;
cout << endl << stu[1].yx_health << endl;
cout << stu[1].v.size();
for(int i = 0;i < stu[1].v.size();i++)
cout << ‘ ‘ << stu[1].v[i].health;
return 0;
}