hdu6396(思维+输入挂)
Posted 2014slx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu6396(思维+输入挂)相关的知识,希望对你有一定的参考价值。
Swordsman Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1740 Accepted Submission(s): 498 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]
对于 k 种防御属性,分开进行从小到大排序,设立 k 个指针从最小处开始往最大处移动,对满足被杀死的条件的属 性进行标记
,当某只 monster 的所有防御属性都被标记时,更新剑士的魔法属性同时更新指针往后移动。时间复 杂度 O(kn log n)
#include<iostream> #include<stdio.h> #include<algorithm> #include<string.h> using namespace std; struct node{ int val; int id; }a[11][100005]; int b[11][100005]; int sum[100005]; bool cmp(node p,node q) { return p.val<q.val; } #define fi(n) FastIO::read(n) namespace FastIO { const int SIZE = 1 << 16; char buf[SIZE], obuf[SIZE], str[60]; int bi = SIZE, bn = SIZE, opt; int read(char *s) { while (bn) { for (; bi < bn && buf[bi] <= ‘ ‘; bi++); if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin); bi = 0; } int sn = 0; while (bn) { for (; bi < bn && buf[bi] > ‘ ‘; bi++) s[sn++] = buf[bi]; if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin); bi = 0; } s[sn] = 0; return sn; } bool read(int& x) { int n = read(str), bf; if (!n) return 0; int i = 0; if (str[i] == ‘-‘) bf = -1, i++; else bf = 1; for (x = 0; i < n; i++) x = x * 10 + str[i] - ‘0‘; if (bf < 0) x = -x; return 1; } }; int main() { int t; fi(t); while(t--) { int n,m; fi(n); fi(m); memset(sum,0,sizeof sum); int pq[6]; for(int i=1;i<=m;i++) { fi(pq[i]); } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { fi(a[j][i].val); a[j][i].id = i; } for(int j=1;j<=m;j++) fi(b[j][i]); } for(int i=1;i<=m;i++) sort(a[i]+1,a[i]+1+n,cmp); int zhizhen[6]={1,1,1,1,1,1}; int pppp=0; while(1) { int pp=0; for(int i=1;i<=m;i++) { while(a[i][zhizhen[i]].val<=pq[i]&&zhizhen[i]<=n) { sum[a[i][zhizhen[i]].id]++; if(sum[a[i][zhizhen[i]].id]==m) { pp++; pppp++; for(int j=1;j<=m;j++) { pq[j]+=b[j][a[i][zhizhen[i]].id]; } } zhizhen[i]++; } } if(pp==0) break; } cout<<pppp<<endl; for(int i=1;i<=m;i++) { if(i!=1) cout<<" "; cout<<pq[i]; } cout<<endl; } return 0; }
以上是关于hdu6396(思维+输入挂)的主要内容,如果未能解决你的问题,请参考以下文章