hdu 1029 Ignatius ans the Princess IV
Ignatius and the Princess IV
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 27227 Accepted Submission(s): 11562
"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<iostream>
#include<stdio.h>
#include<map>
using namespace std;
map <int,int> num;
int main()
{
int n;
while(~scanf("%d",&n))
{
num.clear();
for(int i=;i<n;i++)
{
int tmp;
scanf("%d",&tmp);
num[tmp]++;
}
int times= (n+)/;
int ans= 0x3ffffff;
map<int,int>::iterator iter;
for(iter=num.begin();iter!=num.end();iter++)
{
if(iter->second>=times) ans= iter->first;
}
printf("%d\n",ans);
}
}
hdu 1029 Ignatius ans the Princess IV的更多相关文章
- 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 and the Princess IV (map的使用)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1029 Ignatius and the Princess IV Time Limit: 2000/10 ...
- [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函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...
随机推荐
- [Android] how to get facebook profile
Bundle params = new Bundle(); params.putString("fields", "id,email,gender,cover,pictu ...
- Effective C++ -----条款17:以独立语句将newed对象置入智能指针
以独立语句将newed对象存储于(置入)智能指针内.如果不这样做,一旦异常被抛出,有可能导致难以察觉的资源泄露.
- 【leetcode】Decode Ways(medium)
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- supersr--图形上下文的注意点
- (void)test { // 不要自己调用drawRect:方法的原因: // 当系统调用drawRect:方法之前, 会创建一个与当前UIView的layer相关的图形上下文, 这样就可以保证 ...
- October 1st 2016 Week 40th Saturday
Autumn, the year's last, loveliest smile. 秋,四季流转中的最后一抹,也是最美的那一抹微笑. I love autumn because it is the h ...
- eclipse上安装abator插件
下面是我看了网上的有一点需要强调:网址 http://ibatis.apache.org/tools/abator然后全选,然后是==>重启就好了 eclipse上安装abator插件参考:ht ...
- Git 操作的一些场景
1. 某些不需要的文件/文件夹,如:/build 之类,在添加对应的gitignore之前Push了,导致每次编译都会产生新的文件 解决方法:直接删掉不需要的文件/文件夹,然后push gitigno ...
- iOS自动更新如何实现
APP检测更新可以使用两种方法.第一种是和安卓等系统一样,获取自己服务器的APP版本号与已安装的APP版本号比较:第二种是根据已发布到app store上的应用版本号与已安装的APP版本号比较更新.第 ...
- entOS7安装iptables防火墙,试验未通过
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- jdbc连接oracle数据库
/*** 通过改变配置文件来连接不同数据库*/package com.xykj.jdbc; import static org.junit.Assert.*; import java.io.Input ...