模拟。
注意随从的编号在\(summon\)和\(attack\)随从死亡时都可能改变。
#include <bits/stdc++.h> using namespace std; struct tNode { int attack; int health; }; tNode aPlayer[8]; tNode bPlayer[8]; int aM = 0, bM = 0; int aHealth = 30, bHealth = 30; int main() { int n; scanf("%d", &n); int player = 1; char op[30]; while (n--) { scanf("%s", op); if (op[0] == 's') { int pos, attack, health; scanf("%d%d%d", &pos, &attack, &health); if (player == 1) { for (int i = aM + 1; i >= pos + 1; i--) aPlayer[i] = aPlayer[i - 1]; aPlayer[pos].attack = attack; aPlayer[pos].health = health; aM++; } else { for (int i = bM + 1; i >= pos + 1; i--) bPlayer[i] = bPlayer[i - 1]; bPlayer[pos].attack = attack; bPlayer[pos].health = health; bM++; } } else if (op[0] == 'a') { int attacker, defender; scanf("%d%d", &attacker, &defender); if (player == 1) { if (defender == 0) { bHealth -= aPlayer[attacker].attack; } else { aPlayer[attacker].health -= bPlayer[defender].attack; bPlayer[defender].health -= aPlayer[attacker].attack; if (aPlayer[attacker].health <= 0) { for (int i = attacker; i <= aM - 1; i++) aPlayer[i] = aPlayer[i + 1]; aM--; } if (bPlayer[defender].health <= 0) { for (int i = defender; i <= bM - 1; i++) bPlayer[i] = bPlayer[i + 1]; bM--; } } } else { if (defender == 0) { aHealth -= bPlayer[attacker].attack; } else { aPlayer[defender].health -= bPlayer[attacker].attack; bPlayer[attacker].health -= aPlayer[defender].attack; if (aPlayer[defender].health <= 0) { for (int i = defender; i <= aM - 1; i++) aPlayer[i] = aPlayer[i + 1]; aM--; } if (bPlayer[attacker].health <= 0) { for (int i = attacker; i <= bM - 1; i++) bPlayer[i] = bPlayer[i + 1]; bM--; } } } } else { player *= -1; } } if (aHealth <= 0 || bHealth <= 0) printf("%d\n", player); else printf("0\n"); printf("%d\n", aHealth); printf("%d", aM); for (int i = 1; i <= aM; i++) printf(" %d", aPlayer[i].health); printf("\n"); printf("%d\n", bHealth); printf("%d", bM); for (int i = 1; i <= bM; i++) printf(" %d", bPlayer[i].health); printf("\n"); return 0; }