hdu--1029--思维题

这题 可能是数据不够大的原因吧  一开始我直接sort一遍也过了...

这题 在一天一道算法题里曾经出现过..

    touch  me

O(n)时间复杂度的思想 很cool

 1 /*
 2 #include <iostream>
 3 using namespace std;
 4 
 5 int arr[1000000];
 6 int main()
 7 {
 8     cin.sync_with_stdio(false);
 9     int n;
10     while( cin >> n )
11     {
12         for( int i = 0 ; i<n ; i++ )
13         {
14             cin >> arr[i];
15         }
16         sort(  arr , arr+n );
17         cout << arr[n/2] << endl;
18     }
19     return 0;
20 }
21 */
22 #include <iostream>
23 using namespace std;
24 
25 int main()
26 {
27     cin.sync_with_stdio(false);
28     int n , num , ans , cnt;
29     while( cin >> n )
30     {
31         cnt = 0;
32         while( n-- )
33         {
34             cin >> num;
35             if( 0 == cnt )
36             {
37                 ans = num;
38                 cnt ++;
39             }
40             else
41             {
42                 ans == num ? cnt++ : cnt--;
43             }
44         }
45         cout << ans << endl;
46     }
47     return 0;
48 }
View Code

转载于:https://www.cnblogs.com/radical/p/3866428.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值