HDOJ 1029:Ignatius and the Princess IV 解题报告
来源:互联网 发布:迈达斯软件正版多少钱 编辑:程序博客网 时间:2024/05/01 04:33
题目URL:http://acm.hdu.edu.cn/showproblem.php?pid=1029;
题目大意是找出数组中出现次数超过一半的数。基本思想是每遇到两个不同的数就消掉,设一个计数器就行了。存出现次数最大的那个数的出现次数。当下一个数与当前的数不同时,计数器减一,相同,则加一。
贴个AC代码:
#include<iostream>#include<stdio.h>using namespace std;int main(){int cnt, max, cur, n;while(scanf("%d", &n) != EOF){cnt = 0;for(int i=0; i<n; i++){scanf("%d", &cur);if(!cnt){max = cur;cnt ++;}else if(cur != max) cnt --;else if(cur == max) cnt ++;}//cout << max << endl;printf("%d\n", max);}system("pause");return 0;}
- HDOJ 1029:Ignatius and the Princess IV 解题报告
- 【HDOJ】1029 -> Ignatius and the Princess IV
- hdoj 1029 Ignatius and the Princess IV
- HDOJ 1029 Ignatius and the Princess IV
- HDOJ Ignatius and the Princess IV 1029
- HDOJ 1029 Ignatius and the Princess IV
- hdoj 1029 Ignatius and the Princess IV
- HDOJ 1029 Ignatius and the Princess IV
- hdoj-1029-Ignatius and the Princess IV
- hdoj 1029 Ignatius and the Princess IV
- HDOJ 1029 Ignatius and the Princess IV
- ACM之Ignatius and the Princess IV解题报告
- HDOJ 1028 Ignatius and the Princess III解题报告
- HDOJ-1028-Ignatius and the Princess III 解题报告
- HDOJ 1026 Ignatius and the Princess I 解题报告
- HDOJ 1029 Ignatius and the Princess IV [map]
- hdoj.1029 Ignatius and the Princess IV 20140809
- HDOJ 1029 Ignatius and the Princess IV 【math】
- 在.bat中sleep和kill
- Android远程图片获取和本地缓存
- Linux 上的数据可视化工具
- 循环左移数组
- 心里烦~~~~~~
- HDOJ 1029:Ignatius and the Princess IV 解题报告
- 大型门户网站的十四大技术!!!
- Delphi 2009 – String Performance
- 榨干服务器:让进程运行在指定的CPU
- 利用C语言实现UTF-8与UCS2之间的互相转化
- 使用DJ java Decomplier 将整个jar包反编译成源文件
- 算法与数据结构注意----待续
- Lambda 表达式
- 调试kernel的开启全部的打印的技巧