kuangbin 专题

这题,有很多种解法。

第一种:

直接比较每个数出现次数。

 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define clc(a,b) memset(a,b,sizeof(a))
const int maxn=;
int a[maxn];
int b[maxn];
int main()
{
int n; while(~scanf("%d",&n))
{
clc(b,);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
b[a[i]]++;
}
int maxx=-;
int ans;
for(int i=;i<;i++)
{
if(maxx<b[i])
{
maxx=b[i];
ans=i;
}
}
printf("%d\n",ans);
}
return ;
}

第二种:

应为输出至少(n+1)/2次的数,所以,最后result一定是要求的数。

 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define clc(a,b) memset(a,b,sizeof(a))
const int maxn=;
int a[maxn];
int b[maxn];
int main()
{
int n,i;
int t;
int cnt;
int result;
while(scanf("%d",&n)!=EOF)
{
cnt=;
for(i=; i<n; i++)
{
scanf("%d",&t);
if(cnt==)
{
cnt=;
result=t;
}
else
{
if(t==result)cnt++;
else cnt--;
}
}
printf("%d\n",result);
}
return ;
}

HDU 1029 Ignatius and the Princess IV DP的更多相关文章

  1. HDU 1029 Ignatius and the Princess IV --- 水题

    HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...

  2. 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 ...

  3. 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 ...

  4. hdu 1029 Ignatius ans the Princess IV

    Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K ( ...

  5. [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 ...

  6. HDU 1029 Ignatius and the Princess IV (动态规划、思维)

    Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K ( ...

  7. HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)

    此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can nev ...

  8. HDU 1029 Ignatius and the Princess IV

    解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...

  9. HDU 1029 Ignatius and the Princess IV(数论)

    #include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...

随机推荐

  1. hdu 4665

    转载一下  用的搜索   竟然过了 ............代码 ....... #include<stdio.h> #include<string.h> #include&l ...

  2. Akka的fault tolerant

    要想容错,该怎么办? 父actor首先要获知子actor的失败状态,然后确定该怎么办, “怎么办”这回事叫做“supervisorStrategy".   // Restart the st ...

  3. codeforces #309 div1 A

    先说我的解法吧 首先设f(i,j)表示选了前i个球且j种颜色都已经选完了的方案数 这显然是可以随便转移的 #include<cstdio> #include<cstring> ...

  4. Let's go! (Ubuntu下搭建Go语言环境)

    自2009年Go语言发布以来,我一直在关注Go语言,如今Go语言已经发展到1.2版本,而且也收到越来越多的人关注这门语言.Go语言设计的目的就是为了解决执行数度快但是编译数度并不理想(如C++)以及编 ...

  5. Altium designer中级篇-名称决定多边形连接样式

    在工作中积累了诸多小技巧,可以让工作变的更简单,就比如这个多边形铺铜,与大部分规则的不同之处在于,通过更改多边形的名称,就能达到控制多边形规则的效果.这样多边形铺铜变的及其灵活,下面将对这个经验做一个 ...

  6. Cinema 4D R16安装教程

    CINEMA 4D_百度百科 http://baike.baidu.com/view/49453.htm?fr=aladdin 转自百度贴吧 [教程]Cinema 4D R16新功能介绍及安装教程_c ...

  7. Python Requests库:HTTP for Humans

    Python标准库中用来处理HTTP的模块是urllib2,不过其中的API太零碎了,requests是更简单更人性化的第三方库. 用pip下载: pip install requests 或者git ...

  8. LINQ语句

    http://wenku.baidu.com/link?url=hPKqDWql7DNr6W2MsINakjRYYNXmXywB_U3h9FFMeFjcToYpusI2fYKgHjZSRq7r3ULG ...

  9. 排查Java线上服务故障的方法和实例分析

    前言 作为在线系统负责人或者是一个技术专家,你可能刚刚接手一个项目就需要处理紧急故障,或者被要求帮忙处理一些紧急的故障,这个时候的情景是: (1)你可能对这个业务仅仅是听说过,而不怎么真正了解: (2 ...

  10. JavaScript DOM高级程序设计 4.2 事件类型--我要坚持到底!

    对象事件 load和unload(载入页面的时候调用load,关闭页面的时候调用unload) abort和error 对于载入图像时出现错误的情况,可以使用error事件侦听器来进行说明: ADS. ...