http://acm.hdu.edu.cn/showproblem.php?pid=6396
题意:
给你T组输入。每组输入包含n(n<=1e5),m(1<=m<=5) ,然后给出你的m个属性的初始值。
然后对于n种怪,给出每个怪的m个属性和吃掉它你的m个属性能提高的值。如果你的每种属性都大于等于怪的对应的属性,你就可以吃掉这个怪。求你最多能吃掉多少怪,输出你最终的m个属性的值。
分析:
分析每一种属性,只要满足第一个属性就进入第二个优先队列,直到进入最后一个优先队列,这个时候就满足所有的情况,这个时候刷新目前属性的属性值
代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
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 == '\n' || ch == '\r' || ch == '\t';
}
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;
// void read(int &x){scanf("%d",&x);} //调试的时候用这个,把上面的注释掉。
const int maxn=100010;
int n,m,k,a[maxn][10],b[maxn][10],v[maxn];
typedef pair<int, int> pp;
typedef priority_queue< pp, vector<pp>, greater<pp> > QQ;
QQ q[10],p;
int main()
{
int T,cas=1;
read(T);
while(T--)
{
read(n);read(m);
for(int i=0;i<m;i++) read(v[i]);
for(int i=0;i<m;i++) q[i]=QQ();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
read(a[i][j]);
q[0].push({a[i][0],i});
for(int j=0;j<m;j++)
read(b[i][j]);
}
int ans=0,tmp=-1;
while(tmp!=ans){
tmp=ans;
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({a[x][i+1],x});
}
}
while(!q[m-1].empty()&&q[m-1].top().first<=v[m-1])
{
int x=q[m-1].top().second;q[m-1].pop();
++ans;
for(int i=0;i<m;i++)
v[i]+=b[x][i];
}
}
int flag=1;
printf("%d\n",ans);
for(int i=0;i<m;i++)
if(flag){flag=0;printf("%d",v[i]);}
else printf(" %d",v[i]);
puts("");
}
return 0;
}