ZOJ 3869-Ace of Aces【模拟众数】

梦里梦外; 2022-08-21 14:53 267阅读 0赞

Ace of Aces


Time Limit: 2 Seconds Memory Limit: 65536 KB


There is a mysterious organization called Time-Space Administrative Bureau (TSAB) in the deep universe that we humans have not discovered yet. This year, the TSAB decided to elect an outstanding member from its elite troops. The elected guy will be honored with the title of “Ace of Aces”.

After voting, the TSAB received N valid tickets. On each ticket, there is a number Ai denoting the ID of a candidate. The candidate with the most tickets nominated will be elected as the “Ace of Aces”. If there are two or more candidates have the same number of nominations, no one will win.

Please write program to help TSAB determine who will be the “Ace of Aces”.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains an integer N (1 <= N <= 1000). The next line contains N integers Ai (1 <= Ai <= 1000).

Output

For each test case, output the ID of the candidate who will be honored with “Ace of Aces”. If no one win the election, output “Nobody” (without quotes) instead.

Sample Input

  1. 3
  2. 5
  3. 2 2 2 1 1
  4. 5
  5. 1 1 2 2 3
  6. 1
  7. 998

Sample Output

  1. 2
  2. Nobody
  3. 998

Author: JIANG, Kai

Source: The 12th Zhejiang Provincial Collegiate Programming Contest

解题思路:

找到出现次数最多的数,如果有多个就输出Nobody。

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. using namespace std;
  5. int map[50000];
  6. int main()
  7. {
  8. int t;
  9. scanf("%d",&t);
  10. while(t--)
  11. {
  12. int n;
  13. scanf("%d",&n);
  14. memset(map,0,sizeof(map));
  15. for(int i=0;i<n;i++)
  16. {
  17. int aa;
  18. scanf("%d",&aa);
  19. map[aa]++;
  20. }
  21. int max=-1;
  22. int ans;
  23. int ge=0;
  24. for(int i=1;i<=1200;i++)
  25. {
  26. if(map[i]>max)
  27. {
  28. max=map[i];
  29. ge=0;
  30. ans=i;
  31. }
  32. if(map[i]==max)
  33. {
  34. ge++;
  35. }
  36. }
  37. if(ge>1)
  38. {
  39. printf("Nobody\n");
  40. }
  41. else
  42. {
  43. printf("%d\n",ans);
  44. }
  45. }
  46. return 0;
  47. }

发表评论

表情:
评论列表 (有 0 条评论,267人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ACE简介

    [ACE][] 全称 ADAPTIVE Communication Environment(自适应的网络通讯环境),其中 ADAPTIVE 的全称A Dynamically A

    相关 AC自动机

    要学会AC自动机,我们必须知道什么是Trie,也就是字典树。最好对KMP算法也有些了解。Trie树和KMP算法我之前博客都有写过,感兴趣的可以看看。 简单叙述下问题

    相关 AC代码

    ............此处省略一万分AC代码         加油咯!!!代码还是尽量自己写,看别人的博客不是不可以,看别人的代码也不是不可以,如果你不看

    相关 DACL SACL ACE

    任意访问控制列表( Discretionary ACL )、系统访问控制列表( System ACL )。任意访问控制列表包含了用户和组的列表,以及相应的权限,允许或拒绝。每一