0519 G2n#W2A-C Ignatius and the Princess IV
来源:互联网 发布:linux开启防火墙命令 编辑:程序博客网 时间:2024/06/05 19:52
摘要:找出给定数据中出现次数最多的数
原题目:HDU - 1029
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.
"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.
"But what is the characteristic of the special integer?" Ignatius asks.
"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.
Can you find the special integer for Ignatius?
"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.
"But what is the characteristic of the special integer?" Ignatius asks.
"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.
Can you find the special integer for Ignatius?
51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1
351来源: https://cn.vjudge.net/problem/description/6541?1494775543000
题目理解:对给出的数进行计数 并时刻关注当前出现次数最多的数。使用map来帮忙储存。
注意:给出的数据范围并没有确定,刚开始没有get到这个点。WA了好久
2017 05 19
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <memory.h>
#include <map>
using namespace std;
map<int,int> N;
int main(){
int n,t,ans=0;
while(~scanf("%d",&n)){
N.clear();ans=0;N[0]=0;
for(int i=0;i<n;i++){
scanf("%d",&t);
N[t]++;
if(N[ans]<N[t]) ans=t;
}
printf("%d\n",ans);
}
}
阅读全文
0 0
- 0519 G2n#W2A-C Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- 4.6内部类
- c++primer p101 3.4.2 练习3.24 未完成 很多问题
- Ubuntu 16.04下LNPM开发环境搭建(Linux + Nginx + PHP + MySQL)及一些概念总结
- 多系统端的上网利器 ShadowSocks,影梭
- jsp简洁左侧面板
- 0519 G2n#W2A-C Ignatius and the Princess IV
- 双向链表的插入与删除节点
- tomcat设置直接通过域名访问项目(不需要接 /项目名)
- js 数组
- 【知识库】--JVM 原理指导(java8 )(208)
- asla架构和alsa-lib音频库的移植
- POJ 3616 Milking Time——区间DP
- 刨根究底字符编码之零——前言
- STL中stack(栈)的用法