CCF_炉石传说

该编程题主要考察的是数据结构的使用,一个好的数据结构处理问题来得心应手
我是通过利用C++中原有的list数据结构(大体上相当于一个双向链表)解决该问题的,其中list的每个元素需保存角色和随从的position、attack、health。

#include<iostream>
#include<string>
#include<list>

using namespace std;

class AI{
public:
    int position;
    int attack;
    int health;
    AI(int p,int a,int h){
        position=p;
        attack=a;
        health=h;
    }
};

typedef list<AI> LISTAI;

int main()
{
    int n;
    cin>>n;
    LISTAI pet_one,pet_two;
    pet_one.push_front(AI(0,0,30));
    pet_two.push_front(AI(0,0,30));
    LISTAI::iterator ite;
    string action;
    LISTAI *pet_att=&pet_one;
    LISTAI *pet_def=&pet_two;
    for(int i=0;i<n;i++){
        cin>>action;
        if(action=="summon"){
            int p,a,h,tag=0;
            cin>>p>>a>>h;
            AI temp(p,a,h);
            for(ite=pet_att->begin();ite!=pet_att->end();++ite){
                if(ite->position==p){
                    pet_att->insert(ite,temp);
                    tag=1;
                    while(ite!=pet_att->end()){
                        ite->position++;
                        ite++;
                    }
                break;
                }
            }
            if(tag!=1) pet_att->push_back(temp);
        }
        else if(action=="attack"){
            int att,def;
            cin>>att>>def;
            LISTAI::iterator ite_att,ite_def;
            for(ite_att=pet_att->begin();ite_att!=pet_att->end();++ite_att)
                if(ite_att->position==att) break;
            for(ite_def=pet_def->begin();ite_def!=pet_def->end();++ite_def)
                if(ite_def->position==def) break;
            ite_att->health-=ite_def->attack;
            ite_def->health-=ite_att->attack;
            if(ite_att->health<=0){
                ite_att=pet_att->erase(ite_att);
                for(;ite_att!=pet_att->end();++ite_att)
                    ite_att->position--;
            }
            if(ite_def->position!=0&&ite_def->health<=0){
                ite_def=pet_def->erase(ite_def);
                for(;ite_def!=pet_def->end();++ite_def)
                    ite_def->position--;
            }
            else if(ite_def->position==0&&ite_def->health<=0){
                break;
            }
        }
        else if(action=="end"){
            LISTAI *pp=pet_att;
            pet_att=pet_def;
            pet_def=pp;
        }
    }
    if(pet_one.begin()->health<=0) cout<<-1<<endl;
    else if(pet_two.begin()->health<=0) cout<<1<<endl;
    else cout<<0<<endl;
    ite=pet_one.begin();
    cout<<ite->health<<endl;
    ite++;
    cout<<pet_one.size()-1;
    for(;ite!=pet_one.end();++ite){
        cout<<" "<<ite->health;
    }
    cout<<endl;
    ite=pet_two.begin();
    cout<<ite->health<<endl;
    ite++;
    cout<<pet_two.size()-1;
    for(;ite!=pet_two.end();++ite){
        cout<<" "<<ite->health;
    }
    cout<<endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ccf_offline_stage1_train.csv是中国计算机大赛(CCF)的离线阶段一训练数据集。该数据集是CCF比赛组织方提供给参赛选手进行机器学习和数据挖掘训练的文件。 此数据集包含了2016年至2017年之间顾客线下购买行为的信息。具体而言,它包含了购买券的用户ID、商户ID、交易时间、优惠券ID以及是否使用优惠券等信息。 通过这个数据集,我们可以进行很多有趣的分析和预测。例如,我们可以利用用户的购买行为,预测用户对不同商户的购买意愿,从而帮助商户制定更加精准的促销策略。我们还可以通过分析使用优惠券与不使用优惠券之间的购买行为差异,评估优惠券的推广效果。此外,我们可以根据用户的购买行为数据,对用户进行分类,从而进一步了解不同类型用户的消费习惯。 当然,使用这个数据集进行分析也存在一些挑战和限制。首先,它只包含了线下购买行为的信息,而忽略了线上购买行为。其次,数据集中的一些特征可能存在缺失或错误,需要在使用前进行数据清洗和预处理。此外,数据集的规模可能相对较小,可能需要进一步收集更多样本进行分析和训练。 总之,ccf_offline_stage1_train.csv是一个有价值的数据集,可以被用来进行用户行为分析、预测和商业决策支持。通过深入挖掘这些数据,我们可以更好地理解顾客行为,并制定更有效的营销策略。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值