CCF CSP 201609-3:炉石传说

题目描述很长,我这里就省略了,直接上代码:

#include <bits/stdc++.h>

using namespace std;

void output(vector< pair<int, int> > v){
	cout << v[0].first << endl;
	cout << v.size()-1 << " ";
	for(int i = 1; i < v.size(); i++){
		cout << v[i].first << " ";
	}
	cout << endl;
}

//炉石传说 
int main(){
	int n;
	cin >> n;
	vector< pair<int, int> > a;
	vector< pair<int, int> > b;
	a.push_back(pair<int, int>(30, 0));
	b.push_back(pair<int, int>(30, 0));
	
	int turn = 1, result;
	for(int i = 0; i < n; i++){
		string action;
		cin >> action;
		if(action == "summon"){
			int p, att, h;
			cin >> p >> att >> h;
			if(turn == 1){
				a.insert(a.begin()+p, pair<int, int>(h, att));
			}
			else if(turn == -1){
                b.insert(b.begin()+p, pair<int, int>(h, att));				
			}
		}
		if(action == "attack"){
			int att, def;
			cin >> att >> def;
			if(turn == 1){
				a[att].first -= b[def].second;
				b[def].first -= a[att].second;
				if(a[att].first <= 0 && att){
					a.erase(a.begin()+att);
				}
				if(b[def].first <= 0 && def){
					b.erase(b.begin()+def);
				}
			}
			else if(turn == -1){
				b[att].first -= a[def].second;
				a[def].first -= b[att].second;	
				if(b[att].first <= 0 && att){
					b.erase(b.begin()+att);
				}
				if(a[def].first <= 0 && def){
					a.erase(a.begin()+def);
				}			
			}
			if(a[0].first <= 0 || b[0].first <= 0) break;
		}
		if(action == "end"){
			turn = 0 - turn;
		}		
	}
	
	if(a[0].first > 0 && b[0].first <= 0) result = 1;
	else if(a[0].first <= 0 && b[0].first > 0) result = -1;
	else result = 0;
	cout << result << endl;
	output(a);
	output(b);

	return 0;		
} 

个人心得:

这道题我修改了很多遍,用了vector也用过list,但是都只有80分,后来才发现是我result的取值出现了问题= =

	if(a[0].first && b[0].first) result = 0;
	else  result = a[0].first > b[0].first? 1 : -1;

这是我之前的写法,因为我觉得平局的情况只有两个英雄都活着这种可能,不可能两个都死了,因为只有随从有攻击力。然后如果没有都活着那就是死了一个,一正一负肯定是大的那个赢了,现在我还是不懂为什么这种想法是错的orz......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值