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 v1≥ai,1v1≥ai,1 and v2≥ai,2v2≥ai,2 and v3≥ai,3v3≥ai,3 and …… and vk≥ai,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 (1≤n≤105,1≤k≤51≤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,j≤109vj+∑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 v′1,v′2,v′3,…,v′kv1′,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 1Sample Output
3 23 8 4Hint
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
- 優先隊列循環模擬每個屬性,滿足當前屬性的妖怪進入這個隊列,直到最后一個隊列沒有怪物,每次技能加上最后一個隊列的怪物的加成
- 這個題要加上讀寫掛,如果你寫的代碼超時,先試試我這個掛
總結
以上是生活随笔為你收集整理的HDU Problem - 6396 Swordsman(优先队列,模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU Problem - 5101 S
- 下一篇: HDU Problem - 3763 C