csp201609-3-炉石传说

问题描述

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

Sample Input

8
summon 1 3 6
summon 2 4 2
end
summon 1 4 5
summon 1 2 1
attack 1 2
end
attack 1 1

Sample Output

0
30
1 2
30
1 2

在这里插入图片描述

解题思路以及关键代码

因为有很多插入删除操作,此题采用vector很方便。
要注意一个坑 !!!不要把英雄像删随从一样删掉了!英雄和随从死亡的判定是生命值h<=0。
如果英雄死亡,不会有后续操作,所以不用特判来break。

全部代码

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

struct node
{
    int hx,ax;
};
vector<node> fo1,fo2;//0-7
bool flag=true;
void func(const string &s)
{
    if(s=="summon")
    {
        int pos,at,he;
        cin>>pos>>at>>he;
        if(flag) 
        	fo1.insert(fo1.begin()+pos,{he,at});
        else 
        	fo2.insert(fo2.begin()+pos,{he,at});
    }
    else if(s=="attack")
    {
        int ater,defer;
        cin>>ater>>defter;
        if(!flag) swap(ater,defer);
        fo1[ater].hx-=fo2[defer].ax;
        fo2[defer].hx-=fo1[ater].ax;
        if(fo1[ater].hx<=0 && ater!=0) 
        	fo1.erase(fo1.begin()+ater);
        if(fo2[defer].hx<=0 && defer!=0) 
        	fo2.erase(fo2.begin()+defer);
    }
    else if(s=="end") flag=!flag;
}
int main()
{
    int n;
    cin>>n;
    fo1.insert(fo1.begin(),{30,0});
    fo2.insert(fo2.begin(),{30,0});
    for (int i=1; i<=n; i++)
    {
        string s; cin>>s;
        func(s);
    }
    if(fo1[0].hx<=0) 
    	printf("-1\n");
    else if(fo2[0].hx<=0) 
    	printf("1\n");
    else 
    	printf("0\n");
    printf("%d\n%lu",fo1[0].hx,fo1.size()-1);
    for (int i=1; i<fo1.size(); i++) 
    	printf(" %d",fo1[i].hx); printf("\n");
    printf("%d\n%lu",fo2[0].hx,fo2.size()-1);
    for (int i=1; i<fo2.size(); i++) 
    	printf(" %d",fo2[i].hx); printf("\n");
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值