题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4907
1 5 5 1 2 3 5 6 1 2 3 4 5
4 4 4 4 7
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define MAXN 200017 int hash[MAXN], te[MAXN]; int main() { int t; int n, m; int ti, tt; int i; scanf("%d",&t); while(t--) { memset(hash,0,sizeof(hash)); scanf("%d%d",&n,&m); for(i = 0; i < n; i++) { scanf("%d",&tt); hash[tt]++; } int x = MAXN+1; for(i = MAXN; i > 0; i--) { if(hash[i]) { te[i] = x; } else { te[i] = i; x = i; } } for(i = 0; i < m; i++) { scanf("%d",&ti); printf("%d\n",te[ti]); } } return 0; }
hdu 4907 Task schedule(哈希运用),布布扣,bubuko.com
原文地址:http://blog.csdn.net/u012860063/article/details/38369037