zoukankan      html  css  js  c++  java
  • hdu 1029 Ignatius and the Princess IV DP

    Ignatius and the Princess IV

    Time Limit: 1 Sec  Memory Limit: 256 MB

    题目连接

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

    Description

    "OK, you are not too bad, em... But you can never pass the next test." feng5166 says.

    "I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.

    "But what is the characteristic of the special integer?" Ignatius asks.

    "The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.

    Can you find the special integer for Ignatius?

    Input

    The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.

    Output

    For each test case, you have to output only one line which contains the special number you have found.

    Sample Input

    5 1 3 2 3 3 11 1 1 1 1 1 5 5 5 5 5 5 7 1 1 1 1 1 1 1

    Sample Output

    3 5 1

    HINT

    题意

    给你n个数,让你找到重复半数以上的数

    题解:

    直接暴力统计就好啦,因为重复半数以上,就说明这种数是最多的,所以遇到这个数就++,没遇到就--

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    //**************************************************************************************
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    
    int main()
    {
        int cnt=0;
        int ans=0,a,n;
        while(scanf("%d",&n)!=EOF)
        {
            cnt=0;
            ans=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d",&a);
                if(cnt==0)
                {
                    ans=a;
                    cnt++;
                }
                else
                {
                    if(a==ans)
                        cnt++;
                    else
                        cnt--;
                }
            }
            printf("%d
    ",ans);
    
        }
    }
  • 相关阅读:
    MySQL基础之 逻辑运算符
    MySQL基础之 如何删除主键
    MySQL基础之 AUTO_INCREMENT
    MySQL基础之 支持的数据类型
    TiDB数据库集群安装以及注意事项
    PgSQL基础之 pgsql与mysql的简单区别
    PgSQL基础之 安装postgresql数据系统
    SPRING IN ACTION 第4版笔记-第五章BUILDING SPRING WEB APPLICATIONS-003-示例项目用到的类及配置文件
    SPRING IN ACTION 第4版笔记-第五章BUILDING SPRING WEB APPLICATIONS-002-Controller的requestMapping、model
    SPRING IN ACTION 第4版笔记-第五章Building Spring web applications-001-SpringMVC介绍
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4453254.html
Copyright © 2011-2022 走看看