PAT甲級 1054 The Dominant Color (20分) (模擬)

題目鏈接:傳送門

思路:直接存儲數字出現次數,保存一個出現次數最大的數即可。(題意是選取佔得面積大於50%的,但是其實選取最大的也行,應爲題目應該是保證一定有大於50%的數)

代碼:

#include <bits/stdc++.h>

using namespace std;

map <int , int> mp;


int main() {
	int n , m;
	ios::sync_with_stdio(0);
	cin >> m >> n;
	int mm = 0 , ans = 0;
	for(int i = 0 ; i < n ; i++) {
		for(int j = 0 ; j < m ; j++) {
			int t;
		    cin >> t;
		    mp[t]++;
		    int tmp = mp[t];
		    if(mm < tmp) { 
		    	mm = tmp;
				ans = t;
			}
		}
	}
	cout << ans << "\n";
	return 0;
} 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章