Swordsman
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1725 Accepted Submission(s): 493
Problem Description
Lawson is a magic swordsman with k kinds of magic attributes v1,v2,v3,…,vk. Now Lawson is faced with n monsters and the i-th monster also has k kinds of defensive attributes ai,1,ai,2,ai,3,…,ai,k. If v1≥ai,1 and v2≥ai,2 and v3≥ai,3 and … and vk≥ai,k, Lawson can kill the i-th monster (each monster can be killed for at most one time) and get EXP from the battle, which means vj will increase bi,j for j=1,2,3,…,k.
Now we want to know how many monsters Lawson can kill at most and how much Lawson's magic attributes can be maximized.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line has two integers n and k (1≤n≤105,1≤k≤5).
The second line has k non-negative integers (initial magic attributes) v1,v2,v3,…,vk.
For the next n lines, the i-th line contains 2k non-negative integers ai,1,ai,2,ai,3,…,ai,k,bi,1,bi,2,bi,3,…,bi,k.
It's guaranteed that all input integers are no more than 109 and vj+∑i=1nbi,j≤109 for j=1,2,3,…,k.
It is guaranteed that the sum of all n ≤5×105.
The input data is very large so fast IO (like `fread`) is recommended.
Output
For each test case:
The first line has one integer which means the maximum number of monsters that can be killed by Lawson.
The second line has k integers v′1,v′2,v′3,…,v′k and the i-th integer means maximum of the i-th magic attibute.
Sample Input
1 4 3 7 1 1 5 5 2 6 3 1 24 1 1 1 2 1 0 4 1 5 1 1 6 0 1 5 3 1
Sample Output
3 23 8 4
Hint
For the sample, initial V = [7, 1, 1] ① kill monster #4 (6, 0, 1), V + [5, 3, 1] = [12, 4, 2] ② kill monster #3 (0, 4, 1), V + [5, 1, 1] = [17, 5, 3] ③ kill monster #1 (5, 5, 2), V + [6, 3, 1] = [23, 8, 4] After three battles, Lawson are still not able to kill monster #2 (24, 1, 1) because 23 < 24.
Source
2018 Multi-University Training Contest 7
Recommend
chendu | We have carefully selected several similar problems for you: 6396 6395 6394 6393 6392
题意:打怪升级,给你k个数据,每个数据都大于怪物的数据才可以打败他,打败怪物之后k个数据都会升级bi,求最后打败怪物的数量和最后的k个数据的最终值。
题解:由于题目输入太庞大,普通输入肯定TLE,之后用了百度之星的输入还是TLE,就只能用快速IO输入了。打怪过程直接暴力一遍一遍循环,每次循环打一个怪物,直到打不了或打完了就输出答案。
#include<bits/stdc++.h>
using namespace std;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq[6];
const int N = 1e5;
int n,k,v[10];
int a[N+5][10],b[N+5][10];
namespace IO{
const int MX = 4e7;
char buf[MX];
int c,sz;
void begin(){
c = 0;
sz = fread(buf,1,MX,stdin);
}
inline bool read(int &t){
while(c < sz && buf[c] != '-' && ( buf[c] < '0' || buf[c] > '9')){
c++;
}
if(c >=sz){
return false;
}
bool flag = 0;
if(buf[c] == '-'){
flag = 1,c++;
}
for(t = 0 ; c < sz && '0' <= buf[c] && buf[c] <= '9' ; c++){
t = t * 10 + buf[c] - '0';
}
if(flag){
t = -t;
}
return true;
}
}
int main(){
IO::begin();
int T;
IO::read(T);
while(T--){
for(int i = 1 ; i <= 5 ; i++){
while(!pq[i].empty()){
pq[i].pop();
}
}
IO::read(n);
IO::read(k);
for(int i = 1 ; i <= k ; i++){
IO::read(v[i]);
}
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= k ; j++){
IO::read(a[i][j]);
}
for(int j = 1 ; j <= k ; j++){
IO::read(b[i][j]);
}
}
for(int i = 1 ; i <= n ; i++){
pq[1].push(make_pair(a[i][1],i));
}
bool ok = false;
int cnt = 0;
while(!ok){
ok = true;
for(int j = 1 ; j <= k ; j++){
while(!pq[j].empty()){
int value = pq[j].top().first,id = pq[j].top().second;
if(v[j]<value){
break;
}
if(j==k){
ok = false;
cnt++;
pq[j].pop();
for(int l = 1 ; l <= k ; l++){
v[l]+=b[id][l];
}
}else{
pq[j+1].push(make_pair(a[id][j+1],id));
pq[j].pop();
}
}
}
}
printf("%d\n",cnt);
for(int i = 1 ; i <= k ; i++){
printf("%d",v[i]);
if(i==k){
puts("");
}else{
putchar(' ');
}
}
}
}
百度之星用的输入:
void read(int &x){
char ch = getchar();x = 0;
for (; ch < '0' || ch > '9'; ch = getchar());
for (; ch >='0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}