• HDU6396 (贪心+fread 挂)


    题意:初始值你有k个属性的攻击vi,有n个怪兽,每个怪兽有k种属性的血量ai,并且有k种属性的加成bi,当你的k种属性的值全部大于等于某只怪兽的k种属性的血量,你可以杀死他,并且你的攻击力vi会升级,每种属性的攻击力vi都会加上那只怪兽的bi,求你最多能杀死多少怪兽,且输出最终你的每种属性的攻击力。

    分析:

    由于k最大为5,可以借助最多5个优先队列,每个优先队列qi保存的是所有怪兽的血量ai,先把所有怪兽存在第一个优先队列,然后从第一个优先队列开始,找出所有ai<=vi的怪兽并把它移到下一个优先队列vi+1,当到了最后一个队列,移出去的怪兽代表被杀死,然后更新vi,如果最后一个队列没有移除怪兽,代表已经杀不死任何怪兽了,循环结束;

    !!!!!!!!!1这里要用到fread 快速读入挂。。。  

     普通的快速读入都不行 , 被T成狗。

    #include<bits/stdc++.h>
    int a[100001];
    using namespace std;
    namespace fastIO {
    #define BUF_SIZE 100010
        //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
    };
    using namespace fastIO;
    struct no
    {
    
        int id,val;
        friend bool operator < (no a , no b)
        {
            return a.val>b.val;
        }
    }TT;
    priority_queue<no>que[7];
    struct No
    {
        int HP[6],JHP[6];
        int id;
    }M[100001];
    int main()
    {
        int T,n,k;
        read(T);
      //  printf("%d
    ",T);
        while(T--)
        {
           read(n) , read(k);
           for(int i=1 ; i<=k ; i++)
           {
               while(!que[i].empty()) que[i].pop();
           }
           for(int i=1 ; i<=k ; i++)
           {
               read(a[i]);
           }
           for(int i=1 ; i<=n ; i++)
           {
               for(int j=1 ; j<=k ; j++)
               read(M[i].HP[j]);
               //scanf("%d",&);
               for(int j=1 ; j<=k ; j++)
               read(M[i].JHP[j]);
              // scanf("%d",&);
           }
    
           for(int i=1 ; i<=n ; i++)
           {
               que[1].push({i,M[i].HP[1]});
           }
           int ans=0,per=0;
           while(1)
           {
               for(int i=1 ; i<k ; i++)
               {
                   while(!que[i].empty())
                   {
    
                       TT=que[i].top();
                       int VAL=TT.val;
                       if(VAL>a[i]) break;
                       que[i].pop();// printf("520");
                       que[i+1].push({TT.id,M[TT.id].HP[i+1]});
    
                   }
                }
                   while(!que[k].empty())
                   {
                       TT=que[k].top();
                       int VAL=TT.val;
                       if(VAL>a[k]) break;
                       ans++;
                       for(int i=1 ; i<=k ; i++) a[i]+=M[TT.id].JHP[i];
                       que[k].pop();
                   }
                   if(ans==per) break;
                   per=ans;
    
           }
           printf("%d
    ",ans);
           for(int i=1 ; i<=k ; i++)
           {
               printf("%d",a[i]);
               if(i!=k) printf(" ");
               else puts("");
           }
        }
    }
    View Code
  • 相关阅读:
    Tomcat、Jetty、Undertow、Netty 等容器的区别
    Spring boot整合Swagger2接口文档使用
    为项目配置了Bean,结果Spring Boot并没有扫描到
    yum安装软件所在目录的查询
    LINUX云服务器 安装 nginx
    Cause: org.jetbrains.plugins.gradle.tooling.util.ModuleComponentIdentifierIm Lorg/gradle/api/artifacts/ModuleIdentifier;
    redis数据结构
    linux安装redis
    eclipse项目目录展示结构设置
    tomcat 搭建以及发布配置
  • 原文地址:https://www.cnblogs.com/shuaihui520/p/10439371.html
Copyright © 2020-2023  润新知