hdu_1029_hash/map

http://acm.hdu.edu.cn/showproblem.php?pid=1029

太水了,一次过,直接上代码吧,只想说最愚蠢的hash都要比map快!

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<cmath>
 5 using namespace std;
 6 const int MAX = 999999*2;
 7 const int MOD = 1000007;
 8 int cnt[MAX];
 9 int num[MAX];
10 void ha(int tm)
11 {
12     int tt = tm%MOD;
13     while(num[tt]!=-1) {
14         if(num[tt]==tm) break;
15         tt++;
16     }
17     num[tt] = tm;
18     cnt[tt]++;
19 }
20 int main()
21 {
22     int N;
23     while(~scanf("%d",&N))
24     {
25         memset(num,-1,sizeof(num));
26         memset(cnt,0,sizeof(cnt));
27         int tm;
28         while(N--){
29             scanf("%d",&tm);
30             ha(tm);
31         }
32         int m = 0;
33         int u = -1;
34         for(int i = 0; i < MAX; i++){
35             if(cnt[i]>m) {u = i;m = cnt[i];}
36         }
37         printf("%d
",num[u]);
38     }
39     return 0;
40 }
原文地址:https://www.cnblogs.com/shanyr/p/7216478.html