ZOJ 3869 Ace of Aces

題意:給出一個個數爲n的序列,求出其中的衆數,若有多個衆數,則輸出Nobody

鏈接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5517

思路:排序後統計衆數

注意點:無


以下爲AC代碼:

Run ID Submit Time Judge Status Problem ID Language Run Time(ms) Run Memory(KB) User Name
3945629 2015-04-26 22:50:14 Accepted 3869 C++0x 0 352 luminus
/* 
***********************************************
*# @Author  : Luminous11 ([email protected])
*# @Date    : 2015-04-26 22:41:59
*# @Link    : http://blog.csdn.net/luminous11
*********************************************** 
*/

#include <bits/stdc++.h>
#define clr(a, v) memset( a , v , sizeof(a) )
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1.0);
struct  node
{
	int cnt, k;
};
node num[10005];
bool operator< ( const node & a, const node &b )
{
	return a.cnt > b.cnt;
}
int main()
{
	ios::sync_with_stdio ( false );
	int T;
	scanf ( "%d", &T );
	while ( T -- ){
		int n;
		scanf ( "%d", &n );
		memset ( num, 0, sizeof ( num ) );
		int tmp;
		for ( int i = 0; i < n; i ++ ){
			scanf ( "%d", &tmp );
			num[tmp].cnt ++;
			num[tmp].k = tmp;
		}
		sort ( num, num + 1005 );
		if ( num[0].cnt > num[1].cnt ){
			printf ( "%d\n", num[0].k );
		}
		else{
			printf ( "Nobody\n" );
		}
	}
    return 0;
}


發佈了228 篇原創文章 · 獲贊 5 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章