zoukankan      html  css  js  c++  java
  • 2018 Multi-University Training Contest 7

    优先队列 + 思维

    不然想到肯定是先杀能杀的,这样攻击力就会越来越高,杀的也就越多。

    所以可以开k个优先队列,每一个属性属于一个队列,一开始把所有怪放进第一个队列里,满足击杀条件就一次往之后的队列扔。

    当扔到第k个队列时,如果能击杀,就可以击杀了。

    这样能在最短的时间内统计能够击杀的数量。。

    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define full(a, b) memset(a, b, sizeof a)
    #define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
    using namespace std;
    typedef long long ll;
    inline int lowbit(int x){ return x & (-x); }
    namespace fastIO {
    #define BUF_SIZE 100000
        //fread -> read
        bool IOerror = 0;
        inline char nc() {
            static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
            if(p1 == pend) {
                p1 = buf;
                pend = buf + fread(buf, 1, BUF_SIZE, stdin);
                if(pend == p1) {
                    IOerror = 1;
                    return -1;
                }
            }
            return *p1++;
        }
        inline bool blank(char ch) {
            return ch == ' ' || ch == '
    ' || ch == '
    ' || ch == '	';
        }
        inline void read(int &x) {
            char ch;
            while(blank(ch = nc()));
            if(IOerror) return;
            for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
        }
    #undef BUF_SIZE
    };
    inline int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
    inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
    template<typename T>
    inline T max(T x, T y, T z){ return max(max(x, y), z); }
    template<typename T>
    inline T min(T x, T y, T z){ return min(min(x, y), z); }
    template<typename A, typename B, typename C>
    inline A fpow(A x, B p, C lyd){
        A ans = 1;
        for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
        return ans;
    }
    using namespace fastIO;
    
    const int N = 600006;
    int _, n, k, ad[10], ans;
    struct Monster{
        int ad[10], exp[10];
    }m[N];
    struct Node{
        int val, id;
        Node(int val, int id): val(val), id(id){}
        bool operator < (const Node &rhs) const {
            return val > rhs.val;
        }
    };
    int main(){
    
        for(read(_); _; _ --){
            read(n), read(k), ans = 0;
            for(int i = 1; i <= k; i ++) read(ad[i]);
            for(int i = 1; i <= n; i ++){
                for(int j = 1; j <= k; j ++) read(m[i].ad[j]);
                for(int j = 1; j <= k; j ++) read(m[i].exp[j]);
            }
            priority_queue<Node> pq[k + 1];
            for(int i = 1; i <= n; i ++)
                pq[1].push(Node(m[i].ad[1], i));
            while(true){
                int now = 0;
                for(int i = 1; i < k; i ++){
                    while(!pq[i].empty()){
                        Node cur = pq[i].top();
                        if(ad[i] >= cur.val){
                            pq[i + 1].push(Node(m[cur.id].ad[i + 1], cur.id));
                            pq[i].pop();
                        }
                        else break;
                    }
                }
                while(!pq[k].empty()){
                    Node cur = pq[k].top();
                    if(cur.val > ad[k]) break;
                    for(int i = 1; i <= k; i ++){
                        ad[i] += m[cur.id].exp[i];
                    }
                    now ++;
                    pq[k].pop();
                }
                if(!now) break;
                ans += now;
            }
            printf("%d
    %d", ans, ad[1]);
            for(int i = 2; i <= k; i ++)
                printf(" %d", ad[i]);
            puts("");
        }
        return 0;
    }
    
  • 相关阅读:
    Select2插件的隐藏、设置宽度
    远程登陆Linux服务器
    ECMAScript typeof用法
    Select2异步搜索数据
    ECMAScript 引用类型
    LeetCode 任务调度器-Python3<八>
    sort、sorted高级排序-Python3.7 And 算法<七>
    LeetCode算法笔记目录
    数据结构-Python3.7<三>
    【夯实PHP基础】php开发时遇到白页的调试方法
  • 原文地址:https://www.cnblogs.com/onionQAQ/p/10950713.html
Copyright © 2011-2022 走看看