日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU Problem - 6396 Swordsman(优先队列,模拟)

發布時間:2024/4/18 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU Problem - 6396 Swordsman(优先队列,模拟) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接

Problem Description

Lawson is a magic swordsman with kk kinds of magic attributes v1,v2,v3,,vkv1,v2,v3,…,vk. Now Lawson is faced with nn monsters and the ii-th monster also has kk kinds of defensive attributes ai,1,ai,2,ai,3,,ai,kai,1,ai,2,ai,3,…,ai,k. If v1ai,1v1≥ai,1 and v2ai,2v2≥ai,2 and v3ai,3v3≥ai,3 and and vkai,kvk≥ai,k, Lawson can kill the ii-th monster (each monster can be killed for at most one time) and get EXP from the battle, which means vjvj will increase bi,jbi,j for j=1,2,3,,kj=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 TT, indicating the number of test cases. For each test case:The first line has two integers nn and kk (1n105,1k51≤n≤105,1≤k≤5).The second line has kk non-negative integers (initial magic attributes) v1,v2,v3,,vkv1,v2,v3,…,vk.For the next nn lines, the ii-th line contains 2k2k non-negative integers ai,1,ai,2,ai,3,,ai,k,bi,1,bi,2,bi,3,,bi,kai,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 109109 and vj+i=1nbi,j109vj+∑i=1nbi,j≤109 for j=1,2,3,,kj=1,2,3,…,k.It is guaranteed that the sum of all n 5×105≤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 kk integers v1,v2,v3,,vkv1′,v2′,v3′,…,vk′ and the ii-th integer means maximum of the ii-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.

AC

  • 優先隊列循環模擬每個屬性,滿足當前屬性的妖怪進入這個隊列,直到最后一個隊列沒有怪物,每次技能加上最后一個隊列的怪物的加成
  • 這個題要加上讀寫掛,如果你寫的代碼超時,先試試我這個掛
#include <iostream> #include <stdio.h> #include <map> #include <vector> #include <queue> #include <algorithm> #define N 100005 #define ll long long #define P pair<int, int> #define mk make_pair // 加快讀寫 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;} } using namespace std; int v[10], a[N][15];using namespace IO; int main() { #ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin); #endif begin();priority_queue<P, vector<P>, greater<P> >q[15];int t;read(t);while (t--) {int n, k, sum = 0;read(n);read(k);for (int i = 1; i <= k; ++i) read(v[i]);for (int i = 1; i <= n; ++i) for (int j = 1; j <= 2 * k; ++j) read(a[i][j]);for (int i = 1; i <= n; ++i) {q[0].push(mk(a[i][1], i));}while (1) {// 對隊列進行循環 for (int i = 0; i < k; ++i) {while (! q[i].empty()) {P t = q[i].top();if (t.first > v[i + 1]) break;q[i].pop();q[i + 1].push(mk(a[t.second][i + 2], t.second));}}if (q[k].empty()) break;while (!q[k].empty()) {P t = q[k].top();q[k].pop();for (int i = 1; i <= k; ++i) {v[i] += a[t.second][i + k];}sum++;}}// 注意輸出格式 printf("%d\n%d", sum, v[1]);for (int i = 2; i <= k; ++i) {printf(" %d", v[i]);} printf("\n");// 清空隊列 for (int i = 0; i <= k; ++i) {while (!q[i].empty()) {q[i].pop();}}} return 0; }

總結

以上是生活随笔為你收集整理的HDU Problem - 6396 Swordsman(优先队列,模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。