【CCF】炉石传说 模拟
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<map> #include<vector> using namespace std; int n; string cmd; int now=0; struct node{ int attack; int health; node(int _attack,int _health):attack(_attack),health(_health){} }; vector<node> smn[2]; vector<node>::iterator it; void init(){ for(int i=0;i<2;i++){ smn[i].clear(); smn[i].push_back(node(0,30)); } now=0; } void summon(){ int position,attack,health; cin>>position>>attack>>health; it=smn[now].begin(); smn[now].insert(it+position,node(attack,health)); } void attack(){ int attacker,defender; cin>>attacker>>defender; smn[now][attacker].health-=smn[now^1][defender].attack; smn[now^1][defender].health-=smn[now][attacker].attack; for(int i=0;i<2;i++){ for(it=smn[i].begin()+1;it<smn[i].end();it++){ if((*it).health<=0){ smn[i].erase(it); } } } } void end(){ if(smn[0][0].health<=0&&smn[1][0].health>0){ printf("-1\n"); }else if(smn[0][0].health>0&&smn[1][0].health>0){ printf("0\n"); }else{ printf("1\n"); } for(int i=0;i<2;i++){ printf("%d\n",smn[i][0].health); printf("%d",(int)smn[i].size()-1); for(int j=1;j<(int)smn[i].size();j++){ printf(" %d ",smn[i][j].health); } printf("\n"); } } int main(){ init(); cin>>n; while(n--){ cin>>cmd; if(cmd=="summon"){ summon(); }else if(cmd=="attack"){ attack(); }else if(cmd=="end"){ now^=1; } } end(); return 0; }