其他分享
首页 > 其他分享> > csp 201609-3 炉石传说

csp 201609-3 炉石传说

作者:互联网

csp 201609-3 炉石传说

思路

这道题需要我们定义两个行为,攻击与加兵。

在写题过程中也一定要注意到细节,细节是解决模拟题的关键,一定要对题目有所设计。

代码

#include<iostream>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class solder {
public:
	solder(int a, int b, int c) {
		this->pos = a;
		this->att = b;
		this->hlt = c;
	}
	int hlt;
	int att;
	int pos;
	bool operator < (const solder& s) const {
		return this->pos < s.pos;
	}
};

int t = 0;
vector<vector<solder>> f;

int hlt[2] = { 30, 30 };

void summ(int pos, int att, int hlt) {
	int n = t % 2;
	for (int i = 0; i < f[n].size(); i++) {
		if (f[n][i].pos >= pos) f[n][i].pos++;
	}
	f[n].push_back(solder(pos, att, hlt));
	sort(f[n].begin(), f[n].end());
}

void att(int att, int def) {
	int n = t % 2, m = (t + 1) % 2;
	if (!def) {
		hlt[m] -= f[n][att - 1].att;
	}
	else {
		solder s1 = f[n][att - 1];
		solder s2 = f[m][def - 1];
		int a = s1.hlt - s2.att;
		int b = s2.hlt - s1.att;
		f[n][att - 1].hlt = a;
		f[m][def - 1].hlt = b;
		if (a <= 0) {
			for (int i = att; i < f[n].size(); i++) f[n][i].pos--;
			f[n].erase(f[n].begin() + att - 1);
		}
		if (b <= 0) {
			for (int i = def; i < f[m].size(); i++) f[m][i].pos--;
			f[m].erase(f[m].begin() + def - 1);
		}
	} 
}

void out() {
	if (hlt[0] <= 0) cout << -1 << endl;
	else if (hlt[1] <= 0) cout << 1 << endl;
	else cout << 0 << endl;
	for (int i = 0; i < 2; i++) {
		cout << hlt[i] << endl;
		cout << f[i].size() << " ";
		for (int j = 0; j < f[i].size(); j++) cout << f[i][j].hlt << " ";
		cout << endl;
	}
}

int main() {
	f.resize(2);
	int n; cin >> n;
	getchar();
	for (int i = 0; i < n; i++) {
		int a, b, c;
		string l;
		getline(cin, l);
		char* ch = (char*)l.data();
		if (l[0] == 's') {
			sscanf_s(ch, "summon %d %d %d", &a, &b, &c);
			summ(a, b, c);
		}
		else if (l[0] == 'a') {
			sscanf_s(ch, "attack %d %d", &a, &b);
			att(a, b);
		}
		else {
			t++;
		}
	}
	out();

}

标签:int,炉石,hlt,pos,att,201609,solder,include,csp
来源: https://www.cnblogs.com/Leopard1214/p/15368716.html