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;
    }
  • 相关阅读:
    selenium开发-C#/java/Python
    Web循环监控Java调用 / Java调用.net wcf接口
    网站循环加载监控-C#
    串口通信分析
    windows环境jar包部署到linux服务器,一键操作
    windows环境jar包部署到linux服务器,一键操作(帮助说明)
    Git+TortoiseGit使用帮助
    安装Docker
    MySQL报错信息:Warning: (1366, "Incorrect string value: '\xD6\xD0\xB9\xFA\xB1\xEA...' for column 'VARIABLE_VALUE' at row 489")
    txt文档中文乱码
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4650538.html
Copyright © 2011-2022 走看看