HDU 6396

题意:

n个怪兽,每个怪兽有5个属性,只有当所有的5个属性都大于等于怪兽时,才能消灭怪兽,每消灭一个怪兽,5个属性都会提升一点,求消灭的怪兽数目和最后5个属性的值。

题解:

暴力。。。

我们将消灭一个怪兽分解成5步,即大于等于第1个属性,大于等于第2个属性。。。大于等于第5个属性。

建立5个堆,初始时所有的第1个属性都在第1堆,将能消灭第1个属性的怪兽的第2个属性放到第2堆,相当于消灭了1/5,再将能消灭第2个属性的怪兽的第3个属性放到第3堆,相当于消灭了2/5,以此类推,只有能放入第5堆得怪兽才可能真正被消灭,这时,真正消灭能消灭的怪兽,并增强属性,由于属性增强,原本不能消灭的怪兽可能又能消灭了,这就需要在从第一堆开始重复以上操作。

由于每个怪兽最多出入堆5次,所以时间复杂度为O(5 log n)

代码:

#include<bits/stdc++.h>
#define N 100010
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define cl clear
#define si size
#define lb lowwer_bound
#define eps 1e-8
const LL mod=1e9+7;
using namespace std;
typedef pair<int,int> P;
priority_queue<P,vector<P>,greater<P> >q[5];

int a[N][5],b[N][5],v[5];
namespace IO{
    #define BUF_SIZE 100000
    #define OUT_SIZE 100000
    #define ll long long
    //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;}
            //{printf("IO error!\n");system("pause");for (;;);exit(0);}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline void read(int &x){
        bool sign=0; char ch=nc(); x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
    }
};

int main()
{
    int T;
    IO::read(T);
    while(T--)
    {
        int n,m;
        IO::read(n);IO::read(m);
        for(int i=0;i<m;i++) while(!q[i].empty()) q[i].pop();
        for (int i=0;i<m;i++) IO::read(v[i]);
        for (int i=1;i<=n;i++)
        {
            for (int j=0;j<m;j++) IO::read(a[i][j]);
            for (int j=0;j<m;j++) IO::read(b[i][j]);
            q[0].push(P(a[i][0],i));
        }
        int p=0,ans=0;
        while(1)
        {
            for (int i=0;i<m-1;i++)
            {
                while(!q[i].empty() && q[i].top().first<=v[i])
                {
                    int x=q[i].top().second; q[i].pop();
                    q[i+1].push(P(a[x][i+1],x));
                }
            }
            while (!q[m-1].empty() && q[m-1].top().first<=v[m-1])
            {
                ans++;
                int x=q[m-1].top().second; q[m-1].pop();
                for (int i=0;i<m;i++) v[i]+=b[x][i];
            }
            if (p==ans) break;
            p=ans;
        }
        cout<<ans<<endl;cout<<v[0];
        for (int i=1;i<m;i++) cout<<' '<<v[i];
        cout<<endl;
    }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值