zoukankan      html  css  js  c++  java
  • hdu6396 /// fread()快速读入挂

    题目大意:

    给定n k

    给定主角具有的k种属性

    给定n个怪兽具有的k种属性和打死该怪兽后能得到的k种属性对应增幅

    求主角最多能打死多少怪兽和最终主角的k种属性

    k最大为5 开5个优先队列贪心

    快速读入模板

    #include <bits/stdc++.h>
    using namespace std;
    
    #define reads(n) FastIO::read(n)
    namespace FastIO {
        const int SIZE = 1 << 16;
        char buf[SIZE], obuf[SIZE], str[60];
        int bi = SIZE, bn = SIZE, opt;
        int read(char *s) {
            while (bn) {
                for (; bi < bn && buf[bi] <= ' '; bi++);
                if (bi < bn) break;
                bn = fread(buf, 1, SIZE, stdin);
                bi = 0;
            }
            int sn = 0;
            while (bn) {
                for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];
                if (bi < bn) break;
                bn = fread(buf, 1, SIZE, stdin);
                bi = 0;
            }
            s[sn] = 0;
            return sn;
        }
        bool read(int& x) {
            int n = read(str), bf;
            if (!n) return 0;
            int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1;
            for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
            if (bf < 0) x = -x;
            return 1;
        }
    };
    
    int main()
    {
         int n; reads(n);
         return 0;  
    }
    #include <bits/stdc++.h>
    using namespace std;
    #define LL long long
    #define INF 0x3f3f3f3f
    #define mem(i,j) memset(i,j,sizeof(i))
    const int N=1e5+5;
    
    #define reads(n) FastIO::read(n)
    namespace FastIO {
        const int SIZE = 1 << 16;
        char buf[SIZE], obuf[SIZE], str[60];
        int bi = SIZE, bn = SIZE, opt;
        int read(char *s) {
            while (bn) {
                for (; bi < bn && buf[bi] <= ' '; bi++);
                if (bi < bn) break;
                bn = fread(buf, 1, SIZE, stdin);
                bi = 0;
            }
            int sn = 0;
            while (bn) {
                for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];
                if (bi < bn) break;
                bn = fread(buf, 1, SIZE, stdin);
                bi = 0;
            }
            s[sn] = 0;
            return sn;
        }
        bool read(int& x) {
            int n = read(str), bf;
            if (!n) return 0;
            int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1;
            for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
            if (bf < 0) x = -x;
            return 1;
        }
    };
    
    int n,k;
    int v[6],a[N][11];
    struct NODE{
        int x,id;
        bool operator <(const NODE& p)const {
            return x>p.x;
        }
    };
    priority_queue<NODE> q[6];
    
    int main()
    {
        int t; reads(t);
        while(t--) {
            reads(n); reads(k);
            for(int i=0;i<k;i++)
                while(!q[i].empty()) q[i].pop();
            for(int i=0;i<k;i++)
                reads(v[i]);
            for(int i=0;i<n;i++)
                for(int j=0;j<2*k;j++)
                    reads(a[i][j]);
            for(int i=0;i<n;i++)
                q[0].push({a[i][0],i});
            int ans=0;
            while(1) {
                bool OK=0;
                for(int i=0;i<k;i++) {
                    while(!q[i].empty()) {
                        NODE t=q[i].top();
                        if(t.x<=v[i]) {
                            q[i].pop();
                            if(i==k-1) {
                                ans++; OK=1;
                                for(int j=0;j<k;j++)
                                    v[j]+=a[t.id][j+k];
                            } else {
                                t.x=a[t.id][i+1];
                                q[i+1].push(t);
                            }
                        } else break;
                    }
                }
                if(!OK) break;
            }
            printf("%d
    ",ans);
            for(int i=0;i<k;i++) {
                printf("%d",v[i]);
                if(i==k-1) printf("
    ");
                else printf(" ");
            }
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    inet_ntoa解析
    日语常用计算机词汇
    Visual Studio 2012 : error LNK2026: module unsafe for SAFESEH image
    android异常总结四 :Unexpected text found in layout file: """
    android异常总结三 :R文件丢失
    android异常总结二 :This text field does not specify an inputType or a hint
    android异常总结一 :reslayoutOtherActivity.xml: Invalid file name: must contain only [a-z0-9_.]
    Win8下配置java环境
    CUDA实例练习(五):两数相加
    CUDA实例练习(四):矩阵转置
  • 原文地址:https://www.cnblogs.com/zquzjx/p/10384185.html
Copyright © 2011-2022 走看看