CCF-CSP201609-3 爐石傳說(70分)
阿新 • • 發佈:2018-11-20
#include<iostream> #include<vector> #include<algorithm> using namespace std; struct man { int id; int attack; int life; }; bool cmp(man a,man b) { return a.id<b.id; } vector<man> first,second; int main() { bool who=true; man temp={0,0,30}; first.push_back(temp); second.push_back(temp); int n; cin>>n; while(n>0 && first[0].life>0 && second[0].life>0) { n--; string op; cin>>op; if(who) { if(op=="summon") { int p,a,l; cin>>p>>a>>l; for(int i=1;i<first.size();i++) { if(first[i].id==p) { for(int j=i;j<first.size();j++) first[j].id++; break; } } man temp={p,a,l}; first.push_back(temp); sort(first.begin(),first.end(),cmp); } if(op=="attack") { int me,you,i; cin>>me>>you; first[me].life-=second[you].attack; second[you].life-=first[me].attack; if(first[me].life<=0) { for(i=1;first[i].id!=me;i++); for(int j=i;j<first.size();j++) first[j].id--; first.erase(first.begin()+i); } if(you>0 && second[you].life<=0) { for(i=1;second[i].id!=you;i++); for(int j=i;j<second.size();j++) second[j].id--; second.erase(second.begin()+i); } } } else { if(op=="summon") { int p,a,l; cin>>p>>a>>l; for(int i=1;i<second.size();i++) { if(second[i].id==p) { for(int j=i;j<second.size();j++) second[j].id++; break; } } man temp={p,a,l}; second.push_back(temp); sort(second.begin(),second.end(),cmp); } if(op=="attack") { int me,you,i; cin>>me>>you; second[me].life-=first[you].attack; first[you].life-=second[me].attack; if(second[me].life<=0) { for(i=1;second[i].id!=me;i++); for(int j=i;j<second.size();j++) second[j].id--; second.erase(second.begin()+i); } if(you>0 && first[you].life<=0) { for(i=1;first[i].id!=you;i++); for(int j=i;j<first.size();j++) first[j].id--; first.erase(first.begin()+i); } } } if(op=="end") who=!who; } if(first[0].life<=0) cout<<1<<endl; else if(second[0].life<=0) cout<<-1<<endl; else cout<<0<<endl; cout<<first[0].life<<endl<<first.size()-1; for(int i=1;i<first.size();i++) cout<<" "<<first[i].life; cout<<endl<<second[0].life<<endl<<second.size()-1; for(int i=1;i<second.size();i++) cout<<" "<<second[i].life; return 0; }