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

    大概是CCF 第三题比较简洁的一道题吧

    尽量设计好一个数据结构:

                                          node t[2][10]: 存双方的英雄和随从

                                           int    num[2]: 存隋朝的数量

                                          用p来实现双方的切换,因为有统一 的接口,所以就不用分情况讨论,将两者看出统一

    做了太多PAT ,想着双方同时死亡怎么办,后来想不可能 因为英雄的攻击力为0  

    再次吐槽,PAT真是太多吐槽点

    #include <bits/stdc++.h>
    using namespace std;
    struct node {
        int atk;
        int hel;
    };
    node t[2][10];
    int  num[2];
    int  p,n,flag;
    void _formal (int player,int pos) {
        if (pos==0) {
            if (player) flag=1;
            else        flag=-1;
            return ;
        }
        for (int i=pos;i<num[player];i++)
            t[player][i]=t[player][i+1];
        num[player]--;    
    }
    void _insert (int pos,node tmp) {
        for (int i=num[p];i>=pos;i--) 
            t[p][i+1]=t[p][i];
        t[p][pos]=tmp; num[p]++;
    }
    void _attack (int x,int y) {
        int p1=p,p2=p^1;
        t[p1][x].hel-=t[p2][y].atk;
        t[p2][y].hel-=t[p1][x].atk;
        if (t[p1][x].hel<=0)  _formal (p1,x);
        if (t[p2][y].hel<=0)  _formal (p2,y);
    }
    int main ()
    {
        cin>>n; t[0][0].hel=t[1][0].hel=30;
        while (n--) {
            string str; cin>>str;
            if (flag) continue;
            if (str[0]=='e') p^=1;
            else if (str[0]=='s') {
                int pos,h,a; cin>>pos>>h>>a;
                node tmp={h,a}; _insert(pos,tmp);
            } 
            else {
                int x,y; cin>>x>>y;
                _attack(x,y);
            }
        }
        cout<<flag<<"
    ";
        p=0;
        for (int i=1;i<=2;i++) {
            cout<<t[p][0].hel<<"
    "<<num[p];
            for (int j=1;j<=num[p];j++)
                cout<<" "<<t[p][j].hel;
            cout<<"
    ";
            p^=1;
        }
        return 0;
    }
    抓住青春的尾巴。。。
  • 相关阅读:
    12 go实现几中基本排序算法
    5 控制语句
    9 函数
    4. 常量与运算符
    AI
    AI
    AI
    AI
    ML
    ML
  • 原文地址:https://www.cnblogs.com/xidian-mao/p/10494885.html
Copyright © 2011-2022 走看看