http://acm.hdu.edu.cn/showproblem.php?pid=6396
Title:
Give you group T input. Each group of input contains n (n < = 1E5), m (1 < = m < = 5), and then gives the initial value of your m attributes.
Then for n kinds of monsters, give the M attributes of each monster and the value that can be increased by eating it. If each of your attributes is greater than or equal to the corresponding attribute of the monster, you can eat the monster. Please eat as many monsters as you can, and output the value of your final m attributes.
Analysis:
Analyze each attribute. As long as the first attribute is satisfied, enter the second priority queue until the last priority queue. At this time, all conditions are satisfied. At this time, refresh the attribute values of the current attribute
Code:
#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);} / / use this when debugging, and comment out the above. 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; }