Kuangbin Special Topics
There are many kinds of solutions to this problem.
The first type:
Compares the occurrences of each number directly.
1#include <iostream>2#include <string>3#include <algorithm>4#include <cstdlib>5#include <cstdio>6#include <Set>7#include <map>8#include <vector>9#include <cstring>Ten#include <stack> One#include <cmath> A#include <queue> -#include <bits/stdc++.h> - using namespacestd; the #defineINF 0x3f3f3f3f - #defineLL Long Long - #defineCLC (A, B) memset (A,b,sizeof (a)) - Const intmaxn=1000000; + intA[MAXN]; - intB[MAXN]; + intMain () A { at intN; - - while(~SCANF ("%d",&N)) - { -CLC (b,0); - for(intI=0; i<n;i++) in { -scanf"%d",&a[i]); tob[a[i]]++; + } - intmaxx=-1; the intans; * for(intI=0;i<10000; i++) $ {Panax Notoginseng if(maxx<B[i]) - { themaxx=B[i]; +ans=i; A } the } +printf"%d\n", ans); - } $ return 0; $}
View Code
The second type:
The number should be at least (n+1)/2 times, so the final result must be the number required.
1#include <iostream>2#include <string>3#include <algorithm>4#include <cstdlib>5#include <cstdio>6#include <Set>7#include <map>8#include <vector>9#include <cstring>Ten#include <stack> One#include <cmath> A#include <queue> -#include <bits/stdc++.h> - using namespacestd; the #defineINF 0x3f3f3f3f - #defineLL Long Long - #defineCLC (A, B) memset (A,b,sizeof (a)) - Const intmaxn=1000000; + intA[MAXN]; - intB[MAXN]; + intMain () A { at intn,i; - intT; - intCNT; - intresult; - while(SCANF ("%d", &n)! =EOF) - { inCnt=0; - for(i=0; i<n; i++) to { +scanf"%d",&t); - if(cnt==0) the { *Cnt=1; $result=T;Panax Notoginseng } - Else the { + if(T==result) cnt++; A Elsecnt--; the } + } -printf"%d\n", result); $ } $ return 0; -}
View Code
HDU 1029 Ignatius and the Princess IV DP