• 【hdu 6396】Swordsman


    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    开k个优先队列。每个队列都满足从小到大那种。。 首先将所有的怪物加入到第一个队列中。 然后对于v[i]>=pq[i].top()的怪物,把这个怪物加入到i+1个队列。

    然后每个队列都这么做。
    直到不会有怪物从一个队列转移到另外一个队列为止。
    当某个怪物在第k个队列中也满足转移之后。。那么这个怪物就是能被打败的了。。
    每个队列就是一种检验吧。。。如果k个都能。。那就都满足了。。

    【代码】

    #include <bits/stdc++.h>
    using namespace std;
    
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq[6];
    const int K = 5;
    const int N = 1e5;
    
    int n,k;
    int v[K+5],a[N+5][K+5],b[N+5][K+5];
    
    namespace IO {
        const int MX = 4e7;
        char buf[MX]; int c, sz;
        void begin() {
            c = 0;
            sz = fread(buf, 1, MX, stdin);
        }
        inline bool read(int &t) {
            while(c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++;
            if(c >= sz) return false;
            bool flag = 0; if(buf[c] == '-') flag = 1, c++;
            for(t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++) t = t * 10 + buf[c] - '0';
            if(flag) t = -t;
            return true;
        }
    }
    
    int main()
    {
        //freopen("D:\rush.txt","r",stdin);
        IO::begin();
        int T;
        IO::read(T);
        while (T--){
            for (int i = 1;i <= 5;i++) while (!pq[i].empty()) pq[i].pop();
            IO::read(n);IO::read(k);
            for (int i = 1;i <= k;i++)IO::read(v[i]);
            for (int i = 1;i <= n;i++){
                for (int j = 1;j <= k;j++) IO::read(a[i][j]);
                for (int j = 1;j <= k;j++) IO::read(b[i][j]);
            }
            for (int i = 1;i <= n;i++) pq[1].push(make_pair(a[i][1],i));
            bool ok = false;
            int cnt = 0;
            while (!ok){
                ok = true;
                for (int j = 1;j <= k;j++)
                    while (!pq[j].empty()){
                        int value = pq[j].top().first,id = pq[j].top().second;
                        if (v[j]<value) break;
                        if (j==k){
                            ok = false;
                            cnt++;
                            pq[j].pop();
                            for (int l = 1;l <= k;l++) v[l]+=b[id][l];
                        }else{
                            pq[j+1].push(make_pair(a[id][j+1],id));
                            pq[j].pop();
                        }
                    }
            }
            printf("%d
    ",cnt);
            for (int i = 1;i <= k;i++) {
                printf("%d",v[i]);
                if (i==k) puts("");else putchar(' ');
            }
        }
        return 0;
    }
    
    
  • 相关阅读:
    IDEA 非常重要的一些设置项 → 一连串的问题差点让我重新用回 Eclipse !
    分布式任务调度平台 → XXL-JOB 实战
    JAVA
    Spring boot
    WebStorm如何去掉参数提示?
    JAVA
    redis tools
    解Bug之路-Nginx 502 Bad Gateway(转发)
    Apache Drill – JDBC Interface & Custom Function
    Apache Drill – Querying Complex Data & Data Definition Statements & Querying Data
  • 原文地址:https://www.cnblogs.com/AWCXV/p/9470006.html
Copyright © 2020-2023  润新知