Ignatius and the Princess IV HDU
来源:互联网 发布:监控器无网络视频 编辑:程序博客网 时间:2024/06/04 00:29
题意是n个数,输出出现次数大于n+1/2 的数(n为奇数)
计数输出。。
网上有做法是排序然后直接输出中位数,感觉很有道理。。
#include<bits/stdc++.h>using namespace std;int main(){ int n; ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); while(cin>>n){ map<int,int> mp; int x; for(int i=0;i<n;i++){ cin>>x; mp[x]++; } int ans=0; for(auto it=mp.begin();it!=mp.end();it++){ if(it->second>=(n+1)/2){ ans=it->first; break; } } cout<<ans<<"\n"; } return 0;}
阅读全文
0 0
- hdu 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- Ignatius and the Princess IV hdu 1029
- hdu 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- HDU-1029-Ignatius and the Princess IV
- HDU--1029--Ignatius and the Princess IV
- hdu - 1029 -Ignatius and the Princess IV
- RAID实战
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 05 春申门下三千客,小杜城南五尺天
- leetcode 476 Number Complement
- ROC曲线/AUC值/PR曲线
- Ignatius and the Princess IV HDU
- Android中使用SVG
- 第4章 简单的4位计算机设计及实现
- Hbase结合Mapreduce示例
- 存储过程
- 前端面试题汇总--基础篇
- MS-DOS命令
- tomcat提示:指定的服务未安装
- 【工作笔记】scanf%2d的妙用