纯模拟,虽然写得有点多,但思路算是比较友好。
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;
int main()
{
int n;
cin>>n;
int flag = 1;
pair<int, int> first[10], second[10]; //first先手,second后手
first[0] = make_pair(0, 30);
second[0] = make_pair(0, 30);
bool vis1[10], vis2[10]; //标记具体位置是否为空
memset(vis1, false, sizeof(vis1));
memset(vis2, false, sizeof(vis2));
int cnt1 = 0, cnt2 = 0;
vis1[0] = true;
vis2[0] = true;
for(int i = 0 ; i < n ; ++i)
{
string action;
cin>>action;
//cout<<action<<" "<<cnt1<<" "<<cnt2<<endl;
// cout<<action<<" "<<first[0].second<<" "<<second[0].second<<endl;
int position, attack, health, attacker, defender;
if(action == "summon")
{
cin>>position>>attack>>health;
if(first[0].second > 0 && second[0].second > 0)
{
if(flag > 0)
{
if(vis1[position] == true)
{
for(int j = cnt1 + 1 ; j > position ; --j)
first[j] = first[j - 1];
first[position] = make_pair(attack, health);
vis1[cnt1 + 1] = true;
}
else
{
first[position] = make_pair(attack, health);
vis1[position] = true;
}
cnt1++;
}
else if(flag < 0)
{
if(vis2[position] == true)
{
for(int j = cnt2 + 1 ; j > position ; --j)
second[j] = second[j - 1];
second[position] = make_pair(attack, health);
vis2[cnt2 + 1] = true;
}
else
{
second[position] = make_pair(attack, health);
vis2[position] = true;
}
cnt2++;
}
}
}
else if(action == "attack")
{
cin>>attacker>>defender;
if(first[0].second > 0 && second[0].second > 0)
{
if(flag > 0)
{
first[attacker].second -= second[defender].first;
second[defender].second -= first[attacker].first;
if(first[attacker].second <= 0)
{
vis1[attacker] = false;
if(attacker != 0)
{
for(int j = attacker ; j < cnt1 ; ++j)
first[j] = first[j + 1];
vis1[cnt1] = false;
cnt1--;
}
}
if(second[defender].second <= 0)
{
vis2[defender] = false;
if(defender != 0)
{
for(int j = defender ; j < cnt2 ; ++j)
second[j] = second[j + 1];
vis2[cnt2] = false;
cnt2--;
}
}
}
else if(flag < 0)
{
second[attacker].second -= first[defender].first;
first[defender].second -= second[attacker].first;
//cout<<second[attacker].second<<" "<<first[defender].second<<endl;
if(second[attacker].second <= 0)
{
vis2[attacker] = false;
if(attacker != 0)
{
for(int j = attacker ; j < cnt2 ; ++j)
second[j] = second[j + 1];
vis2[cnt2] = false;
cnt2--;
}
}
if(first[defender].second <= 0)
{
vis1[defender] = false;
if(defender != 0)
{
for(int j = defender ; j < cnt1 ; ++j)
first[j] = first[j + 1];
vis1[cnt1] = false;
cnt1--;
}
}
}
}
}
else if(action == "end")
{
flag = -flag;
}
}
/* for(int i = 1 ; i <= cnt1 ; ++i)
cout<<first[i].second<<" ";
cout<<endl;
for(int i = 1 ; i <= cnt2 ; ++i)
cout<<second[i].second<<" ";
cout<<endl;*/
if(first[0].second <= 0)
cout<<-1<<endl;
else if(second[0].second <= 0)
cout<<1<<endl;
else
cout<<0<<endl;
cout<<first[0].second<<endl;
cout<<cnt1;
for(int i = 1 ; i <= cnt1 ; ++i)
cout<<" "<<first[i].second;
cout<<endl;
cout<<second[0].second<<endl;
cout<<cnt2;
for(int i = 1 ; i <= cnt2 ; ++i)
cout<<" "<<second[i].second;
}