码迷,mamicode.com
首页 > 其他好文 > 详细

hdu_1029_Ignatius and the Princess IV(模拟)

时间:2014-12-25 16:34:03      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

http://acm.hdu.edu.cn/showproblem.php?pid=1029

#include <iostream>
#include <cstring>
using namespace  std;

void f(int *a,int len)
{
    int i = 0;
    int cnt = 1;
    while(i < len)
    {
        int temp = a[i];
        while(a[i] == a[i+1])
        {
            cnt++;
            i++;
        }
        i++;
        if (cnt >= (len+1)/2)
        {
            cout << temp;
            break;
        }
        cnt = 1;
    }
}

int cmp( const void *a , const void *b )
{
    return *(int *)a - *(int *)b;
}

int main()
{
    int n;
    while(cin >> n)
    {
        int *a = new int[999999];
        for (int i = 0;i < n;i++)
        {
            cin >> a[i];
        }
        qsort(a,n,sizeof(a[0]),cmp);
        f(a,n);
        cout << endl;
        delete[] a;
    }
                
    return 0;
}


hdu_1029_Ignatius and the Princess IV(模拟)

标签:

原文地址:http://blog.csdn.net/lyn12030706/article/details/42145993

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!