2018 Multi-University Training Contest 7 - Swordsman
Posted onionqaq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018 Multi-University Training Contest 7 - Swordsman相关的知识,希望对你有一定的参考价值。
优先队列 + 思维
不然想到肯定是先杀能杀的,这样攻击力就会越来越高,杀的也就越多。
所以可以开k个优先队列,每一个属性属于一个队列,一开始把所有怪放进第一个队列里,满足击杀条件就一次往之后的队列扔。
当扔到第k个队列时,如果能击杀,就可以击杀了。
这样能在最短的时间内统计能够击杀的数量。。
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define full(a, b) memset(a, b, sizeof a)
#define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
inline int lowbit(int x){ return x & (-x); }
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
};
inline int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
template<typename T>
inline T max(T x, T y, T z){ return max(max(x, y), z); }
template<typename T>
inline T min(T x, T y, T z){ return min(min(x, y), z); }
template<typename A, typename B, typename C>
inline A fpow(A x, B p, C lyd){
A ans = 1;
for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
return ans;
}
using namespace fastIO;
const int N = 600006;
int _, n, k, ad[10], ans;
struct Monster{
int ad[10], exp[10];
}m[N];
struct Node{
int val, id;
Node(int val, int id): val(val), id(id){}
bool operator < (const Node &rhs) const {
return val > rhs.val;
}
};
int main(){
for(read(_); _; _ --){
read(n), read(k), ans = 0;
for(int i = 1; i <= k; i ++) read(ad[i]);
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= k; j ++) read(m[i].ad[j]);
for(int j = 1; j <= k; j ++) read(m[i].exp[j]);
}
priority_queue<Node> pq[k + 1];
for(int i = 1; i <= n; i ++)
pq[1].push(Node(m[i].ad[1], i));
while(true){
int now = 0;
for(int i = 1; i < k; i ++){
while(!pq[i].empty()){
Node cur = pq[i].top();
if(ad[i] >= cur.val){
pq[i + 1].push(Node(m[cur.id].ad[i + 1], cur.id));
pq[i].pop();
}
else break;
}
}
while(!pq[k].empty()){
Node cur = pq[k].top();
if(cur.val > ad[k]) break;
for(int i = 1; i <= k; i ++){
ad[i] += m[cur.id].exp[i];
}
now ++;
pq[k].pop();
}
if(!now) break;
ans += now;
}
printf("%d\n%d", ans, ad[1]);
for(int i = 2; i <= k; i ++)
printf(" %d", ad[i]);
puts("");
}
return 0;
}
以上是关于2018 Multi-University Training Contest 7 - Swordsman的主要内容,如果未能解决你的问题,请参考以下文章
2018 Multi-University Training Contest 2
2018 Multi-University Training Contest 9
2018 Multi-University Training Contest 4
2018 Multi-University Training Contest 4