zoukankan      html  css  js  c++  java
  • 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
    just follow your heart
  • 相关阅读:
    设置eclipse编码
    前端基础知识
    微信小程序
    jQuery下拉框
    Vue-cli的安装
    vue的数据交互形式
    node安装和小测试
    shui
    JQ-滚动条下拉无限的加载数据
    HTML-video全屏
  • 原文地址:https://www.cnblogs.com/radical/p/3866428.html
Copyright © 2011-2022 走看看