HDU 1029 Ignatius and the Princess IV (map的使用)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=1029
Ignatius and the Princess IV
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 42359 Accepted Submission(s): 18467
"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?
1 3 2 3 3
11
1 1 1 1 1 5 5 5 5 5 5
7
1 1 1 1 1 1 1
5
1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define max_v 125
int main()
{
LL n;
while(~scanf("%I64d",&n))
{
map<LL,LL> mm;
map<LL,LL>::iterator it;
for(LL i=;i<=n;i++)
{
LL x;
scanf("%I64d",&x);
mm[x]++;
}
for(it=mm.begin();it!=mm.end();it++)
{
if(it->second>=(n+)/)
{
cout<<it->first<<endl;
break;
}
}
}
return ;
}
HDU 1029 Ignatius and the Princess IV (map的使用)的更多相关文章
- HDU 1029 Ignatius and the Princess IV --- 水题
HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...
- HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...
- hdu 1029 Ignatius ans the Princess IV
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- [ACM] hdu 1029 Ignatius and the Princess IV (动归或hash)
Ignatius and the Princess IV Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32767K (Ja ...
- HDU 1029 Ignatius and the Princess IV (动态规划、思维)
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)
此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can nev ...
- HDU 1029 Ignatius and the Princess IV DP
kuangbin 专题 这题,有很多种解法. 第一种: 直接比较每个数出现次数. #include<iostream> #include<string> #include< ...
- HDU 1029 Ignatius and the Princess IV(数论)
#include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...
- HDU 1029 Ignatius and the Princess IV
解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...
随机推荐
- 解决javac无效的目标发行版1.8问题
之前遇到了几次这个问题,解决了又忘记了,所以特别记录一下这个问题. 遇到这个问题,改pom文件不行,改project的sdk也不行,后面看到网上说真正的原因是maven的runner的jre的环境依然 ...
- 获取指定包名下继承或者实现某接口的所有类(扫描文件目录和所有jar)
import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.net.JarURLCo ...
- javascript检查数据中是否存在相同的元素
这里是两个用于数组中查找重复元素的demo,可以看看啦 <!DOCTYPE html><html lang="en"><head> <me ...
- csharp: DataTable export to excel,word,csv etc
http://code.msdn.microsoft.com/office/Export-GridView-to-07c9f836 https://exporter.codeplex.com/ htt ...
- cf1043F. Make It One(dp 容斥原理)
题意 题目链接 给出\(n\)个数,问最少选几个数,使他们的\(gcd = 1\) Sol 好神仙啊qwq. 首先,如果答案存在,那么最多为\(7\)(因为前\(7\)个质数乘起来\(>= 3e ...
- The Willpower Instinct(自控力,意志力)
下面是我这几天在读斯坦福大学麦格尼格尔教授的<自控力>这本书的过程中摘抄的部分经典句子,发人深思!有助于帮助我们更好的了解自己. 00 导言:欢迎进入意志力入门 意志力:控制自己的注意力. ...
- UMTSkeeper: keep your UMTS/GPRS/GSM connection alive automatically
UMTSkeeper: keep your UMTS/GPRS/GSM connection alive automatically by Elias from Mintaka This page i ...
- Dubbo框架介绍与安装 Dubbo 注册中心(Zookeeper-3.4.6)
背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. • 单一应用架构 • 当网站流量很小时, ...
- C++ 无名对象
http://blog.sina.com.cn/s/blog_5f0e13360100bxlj.html 可以直接调用构造函数产生无名对象. 例如,下面的代码在函数fn()中,创建了一个无名对象: c ...
- C#中的多线程 - 高级多线程 z
原文:http://www.albahari.com/threading/part4.aspx 专题:C#中的多线程 1非阻塞同步Permalink 之前,我们描述了即使是很简单的赋值或更新一个字段也 ...