zoukankan      html  css  js  c++  java
  • Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力

    B. Amr and The Large Array

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/558/problem/B

    Description

    Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.

    Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.

    Help Amr by choosing the smallest subsegment possible.

    Input

    The first line contains one number n (1 ≤ n ≤ 105), the size of the array.

    The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.

    Output

    Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.

    If there are several possible answers you may output any of them.

    Sample Input

    5
    1 1 2 2 1

    Sample Output

    1 5

    HINT

    题意

    要求找到一个区间,使得包含同样的数最多的最短的区间……

    题意真是蛋疼,不过还好我第一次就读对了

    题解:

    我们直接对于每个数,统计这个数出现的次数,然后再记录仪下开始位置和结束位置,然后跑一法1e6的复杂度就吼了!

    代码

    #include<stdio.h>
    #include<iostream>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    
    struct node
    {
        int x,y,z;
    };
    node a[1000011];
    
    int main()
    {
        for(int i=1;i<=1000001;i++)
            a[i].x=1000011,a[i].y=-1,a[i].z=0;
        int n;
        scanf("%d",&n);
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            int x;
            scanf("%d",&x);
            a[x].x=min(i,a[x].x);
            a[x].y=max(i,a[x].y);
            a[x].z++;
            ans=max(ans,a[x].z);
        }
        int ans1=0,ans2=99999999;
        for(int i=1;i<=1000001;i++)
        {
            if(a[i].z==ans)
            {
                if(ans2-ans1>a[i].y-a[i].x)
                    ans2=a[i].y,ans1=a[i].x;
            }
        }
        cout<<ans1<<" "<<ans2<<endl;
    }
  • 相关阅读:
    记录第一次阿里云服务器部署java web工程的经历
    常用网站……
    根据ID获取CEdit的句柄实例
    (转)MFC中获得各个类的指针/句柄 ID的总结
    (转)DoDataExchange执行时机
    深入浅出Visual_C动态链接库(Dll)编程(宋宝华)----整理(word)
    (转)MFC的一些宏的整理 (DECLARE_DYNCREATE/IMPLEMENT_DYNCREATE)
    Socket 学习入门
    (转) 新的开始之Win7、CentOS 6.4 双系统 硬盘安装
    WIN7下使用VC2010调试uCOS-II 2.91
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4650538.html
Copyright © 2011-2022 走看看