hdu_1029-Ignatius and the Princess IV_201310180916
Ignatius and the Princess IV
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others) Total Submission(s): 13419 Accepted Submission(s): 5419
"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?
#include <stdio.h> typedef struct IN
{
int date;
int num;
}IN;
IN aa[];
int s[]; int cmp(const void *a,const void *b)
{
return *(int *)a - *(int *)b;
} int cmp1(const void *a,const void *b)
{
struct IN *c = (IN *)a;
struct IN *d = (IN *)b;
if(c->num!=d->num)
return c->num - d->num;
else
return c->date - d->date;
}
int main()
{
int N;
while(scanf("%d",&N)!=EOF){
int i,j,count,elem;
memset(aa,,sizeof(aa));
for(i=;i<N;i++)
scanf("%d",&s[i]);
qsort(s,N,sizeof(s[]),cmp);
elem=s[];count=;j=;i=;
while(i<N)
{
aa[j].date = elem;
while(s[i]==elem)
{
count++;
i++;
} aa[j++].num = count;
elem = s[i];
count = ;
}
//for(i=0;i<j;i++)
//printf("%d %d\n",aa[i].date,aa[i].num);
qsort(aa,j,sizeof(aa[]),cmp1);
printf("%d\n",aa[j-].date);
}
return ;
}
hdu_1029-Ignatius and the Princess IV_201310180916的更多相关文章
- hdu 1026(Ignatius and the Princess I)BFS
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu1026.Ignatius and the Princess I(bfs + 优先队列)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- 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 1028 Ignatius and the Princess III-DP
HDU 1028 Ignatius and the Princess III Time Limit:1000MS Memory Limit:32768KB 64bit IO Form ...
- hdu 1028 Ignatius and the Princess III(DP)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- HDU 1027 Ignatius and the Princess II(康托逆展开)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- hdu---------(1026)Ignatius and the Princess I(bfs+dfs)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDU 1029 Ignatius and the Princess IV --- 水题
HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...
随机推荐
- kubernetes Traefik ingress配置详解
理解Ingress 简单的说,ingress就是从kubernetes集群外访问集群的入口,将用户的URL请求转发到不同的service上.Ingress相当于nginx.apache等负载均衡方向代 ...
- Frequent values(线段树+离散化)
http://poj.org/problem?id=3368 题意:给出一个非降序排列的整数数组,对于询问(i,j),输出区间[i,j]中出现最多的值的次数. 思路:经典的RMQ,不过我用线段树做的. ...
- HTML Email 编写指南
今天,我想写一个"低技术"问题. 话说我订阅了不少了新闻邮件(Newsletter),比如JavaScript Weekly.每周收到一封邮件,了解本周的大事. 有一天,我就在想, ...
- 【转】Java中特殊的String类型
Java中String是一个特殊的包装类数据有两种创建形式: String s = "abc"; String s = new String("abc"); 第 ...
- IDEA新项目代码上传到gitlab远程仓库
IDEA新项目代码上传到gitlab远程仓库 具体步骤 创建本地仓库 IDEA:VCS-->Import into Version Control-->Create Git Reposit ...
- 为什么使用HttpServlet?http协议特点、servlet
因为只有HttpServlet是基于http协议,实现Servlet接口,而http协议是短连接协议,能够实现客户端访问服务端后,数据交互后 连接自动断开.同时http协议基于tcp.ip协议,封装了 ...
- Servlet访问路径的两种方式、Servlet生命周期特点、计算服务启动后的访问次数、Get请求、Post请求
Servlet访问路径的两种方式: 1:注解 即在Servlet里写一个@WebServlet @WebServlet("/myServlet") 2:配置web.xml < ...
- CSS3悬浮动画效果
利用CSS3的伪类元素hover以及transform,transition等动画属性,可以做出一些炫酷的动画效果.下面将一些项目中使用到的示例发布出来,供大家一起学习研究.演示地址:runjs. 浏 ...
- SSH Secure Shell Client连接centos6.5时中文字乱码处理
在学习Linux的过程中,最先碰到的是通过SSH终端连接时发现有乱码出现,使用这篇文章先从这里说起. 在 ssh , telnet 终端中文显示乱码解决办法#vim /etc/sysconfig/i1 ...
- ddrmenu
<%@ Register TagPrefix="dnn" TagName="MENU" Src="~/DesktopModules/DDRMen ...