Ace of Aces
来源:互联网 发布:淘宝懒人模板 编辑:程序博客网 时间:2024/05/29 00:31
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 numberAi 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".
There are multiple test cases. The first line of input contains an integer Tindicating the number of test cases. For each test case:
The first line contains an integer N (1 <= N <= 1000). The next line contains Nintegers Ai (1 <= Ai <= 1000).
<h4< dd="">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.
<h4< dd="">352 2 2 1 151 1 2 2 31998<h4< dd="">
2Nobody998
题目大意:先输入一个整数n,表示n个测试数据,其次在数每组测试数据中选的人的标号,输出获得票数最多的那个人,要是最多票数的有2人以上,则输出Nobody;
分析:没啥好分析的,附上代码,挺简单的。
#include <iostream>#include <cstdio>#include <algorithm>#include <string.h>#include <cmath>#include <math.h>using namespace std;int main(){ int n; int a[1001],s[1001]; scanf("%d",&n); { int b; for(int i=0;i<n;i++) { memset(s,0,sizeof(s)); int sum=0,e; scanf("%d",&b); int p=0,q=0,c=0; for(int j=0;j<b;j++) { scanf("%d",&a[j]); s[a[j]]++; if(s[a[j]]>=p) { q=p; p=s[a[j]]; c=a[j]; } } if(p==q) cout<<"Nobody"<<endl; else cout<<c<<endl;// int t=0;// for(int j=0;j<=1000;j++)// {// t=max(t,s[j]);// }// for(int j=0;j<=1000;j++)// {// if(t==s[j])// {// sum++;// e=j;// }// }// if(sum%2==0)// printf("Nobody\n");// else// printf("%d\n",e); } return 0; }}注释的那一部分是我一开始做的时候写的,是错误的。原因是在测试 1 2 3的时候sum是1,然后在寻找投票人数是1的时候,sum就是奇数了,所以导致wrong answer了。没有注释的那个是从网上借鉴来的,这个方法很巧妙,p,q不断刷新,c是存当前投票次数最多的那个人的编号的,也是最终的结果;
这个题重点是掌握a[b[i]]这种计数方法。。
- Ace of Aces
- ZOJ3869 Ace of Aces
- Ace of Aces
- Ace of Aces
- Ace of Aces
- Ace of Aces ZOJ
- Ace of Aces
- zoj 3869 Ace of Aces
- ZOJ 3869 Ace of Aces
- ZOJ-3869 Ace of Aces
- ACM-水题 Ace of Aces
- ZOJ 3869Ace of Aces
- ZOJ 3869-- Ace of Aces
- zoj-3869-Ace of Aces
- ZOJ3869:Ace of Aces(浙江省赛2015)
- 浙江省赛 2015 -> A.Ace of Aces
- ZOJ Problem Set - 3869||Ace of Aces
- ZOJ - 3869 Ace of Aces (水)
- 【二分图】poj 1469 COURSES
- 用于解决AlertDialog中需要向EditText输入内容却不能弹出输入法
- swift 中的标记关键字
- Etcd入门教程
- Python基础 —— 使用 pickle 模块存储数据报错的解决办法
- Ace of Aces
- 下拉刷新
- Dede开发
- 【转】浅谈深拷贝与浅拷贝
- 数据库优化02
- 03_模仿string
- Makefile 使用总结
- 椭圆的曲线模拟
- 链表中环的入口结点