CCF 201609-3 炉石传说 100分

Posted 登登登ccc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CCF 201609-3 炉石传说 100分相关的知识,希望对你有一定的参考价值。

 题目来源:- 计算机软件能力认证考试系统

#include<bits/stdc++.h>

using namespace std;

struct summon {
	int att;//攻击力 
	int hea;//生命值 
	summon(int a,int h):
		att(a),hea(h) {};
};

int main() {
	int n,p,a,h,pos1,pos2;
	string type;
	bool pri=0;//先手标志 
	vector<summon> v1= {summon(0,30)},v2= {summon(0,30)};
	cin>>n;
	while(n--) {
		cin>>type;
		if(type=="summon") {
			cin>>p>>a>>h;
			//ps:emplace(position,element)插入元素后,会把插入位置后的元素自动后移 
			if(pri==0)
				v1.emplace(v1.begin()+p,summon(a,h));
			else
				v2.emplace(v2.begin()+p,summon(a,h));
		} else if(type=="attack") {
			cin>>pos1>>pos2;
			if(pri==0) {
				v1[pos1].hea-=v2[pos2].att;
				v2[pos2].hea-=v1[pos1].att;

			} else {
				v2[pos1].hea-=v1[pos2].att;
				v1[pos2].hea-=v2[pos1].att;
			}

			//攻击结束后判断是否有随从生命值小于0,小于0则从数组中删除
			//ps:erase(iteration)删除元素后,会把删除位置后的元素自动前移 
			for(auto it=v1.begin()+1; it<v1.end(); it++)
				if(it->hea<=0)
					v1.erase(it);
			for(auto it=v2.begin()+1; it<v2.end(); it++)
				if(it->hea<=0)
					v2.erase(it);
		} else {
			pri=!pri;//遇到"end"回合反转 
		}
	}
	
	//第一行输出 
	if(v2[0].hea<=0)
		cout<<"1"<<endl;
	else if(v1[0].hea<=0)
		cout<<"-1"<<endl;
	else
		cout<<"0"<<endl;

	//第二、三行输出 
	cout<<v1[0].hea<<endl;
	cout<<v1.size()-1;
	for(int i=1; i<v1.size(); i++)
		cout<<" "<<v1[i].hea;

	//第四、五行输出 
	cout<<endl<<v2[0].hea<<endl;
	cout<<v2.size()-1;
	for(int i=1; i<v2.size(); i++)
		cout<<" "<<v2[i].hea;

	return 0;
}

以上是关于CCF 201609-3 炉石传说 100分的主要内容,如果未能解决你的问题,请参考以下文章

CCF 201609-3 炉石传说 100分

CCF 201609-3 炉石传说

ccf 201609-3 炉石传说

CCF - 201609-3 - 炉石传说

CCF CSP 201609-3 炉石传说

CCF-CSP题解 201609-3 炉石传说