嘤嘤嘤~~~~· |
SwordsmanTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1759 Accepted Submission(s): 506 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.
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: Output For each test case: 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 |
题意 : 给你个巫师,然后有N个怪物,K种属性,如果你的所有属性比怪物对应属性高,那么就可以沙雕他,并且获得奖励,增加K项属性值,问最后能杀多少,最后的属性是多少。
思路:开k个优先队列,然后分开每个属性考虑,当第一个属性符合条件时,就放进第二个队列,以此类推,直到最后一个,就可以杀掉,然后吃掉属性
这道题收获最大就是这个输入挂了,getchar的都会tle,还是这个文件流快很多。
铁代码
#include <bits/stdc++.h>
#define pii pair<int, int>
#define X first
#define no second
#define maxn 100009
using namespace std;
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 man[5];
struct cmp {
bool operator ()(pii a, pii b) {
return a.X > b.X;
}
};
priority_queue <pii,vector<pii>,cmp>p[5];
struct node {
int a[5],b[5];
} mos[maxn];
int main() {
int T,n,k;
//freopen("E:\\1.txt","r",stdin);
//freopen("E:\\2.txt","w",stdout);
IO::begin();
IO::read(T);
//printf("111\n");
//cout << "1" <<endl;
while(T--) {
for(int i = 0;i < 5;i++){
while(!p[i].empty()){
p[i].pop();
}
}
IO::read(n);
IO::read(k);
for(int j = 0; j < k; j++) {
IO::read(man[j]);
}
for(int i = 1; i <= n; i++) {
for(int j = 0; j < k; j++) {
IO::read(mos[i].a[j]);
}
for(int j = 0;j < k;j++){
IO::read(mos[i].b[j]);
}
}
pii tem;
for(int i = 1;i <= n;i++){
tem.X = mos[i].a[0];
tem.no = i;
p[0].push(tem); // first X
//cout << "tem.X" << tem.X << endl;
}
bool flag = true;
int pos = 0;
int ans = 0;
while(flag){
//cout << "!!!" <<endl;
flag = false;
pos = 0;
for(int i = 0;i < k;i++){
//cout << p[i].top().X << " " << man[i] << endl;
while(!p[i].empty() && p[i].top().X <= man[i]){
flag = true;
tem = p[i].top();
p[i].pop();
if(i == k - 1){
ans++;
for(int j = 0;j < k;j++){
man[j] += mos[tem.no].b[j];
}
}else{
tem.X = mos[tem.no].a[i + 1];
p[i + 1].push(tem);
}
}
}
}
printf("%d\n",ans);
for(int i = 0;i < k;i++){
if(i){
printf(" ");
}
printf("%d",man[i]);
}
puts("");
}
return 0;
}