zoukankan      html  css  js  c++  java
  • CSP201609-3炉石传说

     

     

     

    简单思路:

      我们把每一个角色都看作一个节点,有攻击有血量,然后每一个玩家都维护一个vector就可以了,然后根据操作类型(3)按照题目要求来写出对应过程即可,这道题思路还是简单的。

    代码:

    #include<iostream>
    #include<vector>
    #include<string>
    #include<cstdlib>
     
    using namespace std;
    
    struct node {
        int hth;
        int atk;
        node(int h, int a) : hth(h), atk(a) {}
    };
    
    vector<node> player[2];
    
    int main(){
        
        int N;
        cin >> N;
        int pl = 0;
        player[0].push_back(node(30, 0));
        player[1].push_back(node(30, 0));
        
        for(int n=0; n<N; n++) {
            string options;
            cin >> options;
            if(options == "summon") {
                int pos, h, a;
                cin >> pos >> a >> h;
                player[pl].insert(player[pl].begin()+pos, node(h, a));
            }else if(options == "atk") {
                int att, deff;
                cin >> att >> deff;
                player[pl][att].hth -= player[!pl][deff].atk;
                player[!pl][deff].hth -= player[pl][att].atk;
                if(player[pl][att].hth <= 0) {
                    player[pl].erase(player[pl].begin()+att);
                }
                if(player[!pl][deff].hth <= 0 && deff!=0) {
                    player[!pl].erase(player[!pl].begin()+deff);
                }
            }else if(options == "end") {
                pl = !pl;
            }
        }
        if(player[0][0].hth>0 && player[1][0].hth>0) cout << 0 << endl;
        else if(player[0][0].hth>0) cout << 1 << endl;
        else cout << -1 << endl;
        for(int i=0; i<2; i++) {
            cout << player[i][0].hth << endl;
            cout << player[i].size()-1 << " ";
            for(int j=1; j<player[i].size(); j++) {
                cout << player[i][j].hth << " ";
            }
            cout << endl;
        }
    }
    View Code
  • 相关阅读:
    大道至简第一章和java理论学时第一节。感受。
    jQuery基础
    JavaScript对象及初始面向对象
    使用JavaScript操作DOM
    JavaScript操作BOM对象
    JavaScript基础
    实体之间的对应关系
    MySQL常用函数
    SQL Server中分离附加数据及生成SQL脚本
    C#中子类构造函数
  • 原文地址:https://www.cnblogs.com/Xu-SDU/p/13080368.html
Copyright © 2011-2022 走看看