HDU-1029-Ignatius aned the Princess IV
链接:https://vjudge.net/problem/HDU-1029#author=0
题意:
给你n个数字,请你找出出现至少(n+1)/2次的数字。
思路:
dp,hash超时了,不知道是不是我的问题。
cnt记录数量,
目标数比其他数加起来还多。
所以当cnt为0时当前数为目标数,相同cnt++,不同cnt--。
代码:
#include <iostream>
#include <memory.h>
#include <string>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <cstdio>
using namespace std; typedef long long LL; const int MAXN = 1e5 + 10;
const int INF = 0x7fffffff; int main()
{
int n;
while (~scanf("%d", &n))
//while (cin >> n)
{
int cnt = 0,a,vis;
for (int i = 1;i <= n;i++)
{
scanf("%d", &a);
if (cnt == 0)
{
vis = a;
cnt++;
}
else
{
if (a == vis)
cnt++;
else
cnt--;
}
}
printf("%d\n", vis);
} return 0;
}
HDU-1029-Ignatius aned 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 ...
- 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
解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...
- 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",& ...
随机推荐
- ps 工具栏使用
1:称动工具,快捷键是v,则选中移动工具:按shift和左键,可移动当前层移到另一层的中间对齐.如果不用sfhift键,则只是移动:alt+左键上移动,则复制层:alt+中间滚轮,则为放大和缩小. 2 ...
- git删除某次提交(某个commit)的方法【转】
本文转载自:https://www.36nu.com/post/275 git删除某次提交(某个commit)的方法 疯狂的兔子 发表于 4个月前 阅读 536 收藏 0 推荐 0 评论 0 推荐收藏 ...
- 常用的PHP类库,PHP开发者必备【转】
PHP开发者常用的PHP类库和组件 PDF 生成器 FPDF - 这量一个可以让你生成PDF的纯PHP类库. Excel 相关 你的站点需要生成Excel?没有问题,下面这两个类库可以让你轻松做到这一 ...
- 003-更改pip的源让下载安装更加快捷
1 找到pip目录 C:\Python36\Lib\site-packages\pip\models 2 修改下面的index.py文件 将url设定为 https://pypi.douban.com ...
- H264解码器源码(Android 1.6 版)
H264解码器源码,移植ffmpeg中的H264解码部分到Android,深度删减优化,在模拟器(320x480)中验证通过. 程序的采用jni架构.界面部分,文件读取,视频显示都是用java做的,底 ...
- Code:NFine目录
ylbtech-Code:NFine目录 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylb ...
- VMware桥接模式选择宿主机物理网卡
当宿主机有多块物理网卡时,VMware桥接模式也要根据情况选择使用的物理网卡. 比如宿主机有两块物理网卡,一个连外网,一个连内网,如果想与内网组成局域网就需要选择宿主机的内网网卡,反之选择外网网卡,当 ...
- Indexed DB入门导学(1) – 51CTO.COM
在html 5中,其中一个引人注意的新特性,那就是允许使用Indexed DB.… 查阅全文 ›
- 使用BFG清除git仓库中的隐私文件或大文件
使用git时间不长,在调机械臂项目的时候,由于对TwinCAT3和vs的机制不太了解,没有添加很好的忽略文件(.gitignore).造成git仓库包含了很多没有用的文件,例如vs的sdf文件,Twi ...
- 读取关联数据(EF Core2.1.1)
对象-关系映射框架比如EF有三种 方式使用 模型中的导航属性来加载关联数据. 一..Lazy Loading.(关联数据在访问导航属性时被透明的加载,不需要特别的代码,自动的加载) 当一个实体第一次读 ...