hdoj1029 Ignatius and the Princess IV(对题目的观察?)
来源:互联网 发布:锐捷客户端for mac 编辑:程序博客网 时间:2024/06/05 23:02
这道题以前在408统考的卷子上做过。
首先这道题数据量大,容易报超时。其次我们通过理解题意,知道是要找到出现次数超过一半的数,而且关键在于输入的是奇数个数
这意味着出现次数最多的那个数起码会连着出现两次。
我们用count来筛选,初始值为0,结果变量设为temp,输出当count不为0时的temp值。
注:此题用cin输入也会超时。
#include<stdio.h>int main(){int n,count,a,i,temp;while(scanf("%d",&n)!=EOF){count=0;for(i=0;i<n;i++){scanf("%d",&a);if(count==0){temp=a;count++;}else{if(temp==a)count++;else count--;}}printf("%d\n",temp);}return 0;}
阅读全文
0 0
- hdoj1029 Ignatius and the Princess IV(对题目的观察?)
- HDOJ1029 Ignatius and the Princess IV
- HDOJ1029 Ignatius and his princess IV
- Ignatius and the Princess IV(map)
- Ignatius and the Princess IV(暴力)
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- JMS 之 ActiveMQ
- Spring里PropertyPlaceholderConfigurer类的使用
- 二叉树遍历
- USACO Section 1.1 Greedy Gift Givers
- NOI国家集训队论文分类整理
- hdoj1029 Ignatius and the Princess IV(对题目的观察?)
- 梅尔频率倒谱系数(MFCC)教程
- Git冲突:commit your changes or stash them before you can merge.
- 无序广播
- mac安装sonar和使用---上(默认数据库版)
- 处理大并发之五 使用libevent利器bufferevent
- Maven External Dependency
- narray数组操作:数组长度、合并行元素、平方、平方根、list转化为narray
- android系统 Ethernet 解析