B. Amr and The Large Array(Codeforces Round #312 (Div. 2)+找出现次数最多且区间最小)
1 second
256 megabytes
standard input
standard output
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.
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 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.
- 5
- 1 1 2 2 1
- 1 5
- 5
- 1 2 2 3 1
- 2 3
- 6
- 1 2 2 1 1 2
- 1 5
A subsegment B of an array A from l to r is
an array of size r - l + 1 where Bi = Al + i - 1 for
all 1 ≤ i ≤ r - l + 1
题意:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值。
- #include<iostream>
- #include<algorithm>
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #define N 1000001
- using namespace std;
- int n,m;
- struct node
- {
- int x;
- int y;
- int ans;
- int cnt;
- }q[1000100];
- bool cmp(node a,node b)
- {
- if(a.cnt == b.cnt)
- {
- return a.ans < b.ans;
- }
- return a.cnt > b.cnt;
- }
- int main()
- {
- while(scanf("%d",&n)!=EOF)
- {
- int mm;
- for(int i=0;i<=N;i++)
- {
- q[i].cnt = 0;
- }
- int maxx = 0;
- int a;
- for(int i=1;i<=n;i++)
- {
- scanf("%d",&a);
- if(mm<a)
- {
- mm = a;
- }
- if(q[a].cnt == 0)
- {
- q[a].x = i;
- q[a].y = i;
- q[a].ans = 0;
- q[a].cnt++;
- }
- else
- {
- q[a].cnt++;
- q[a].y = i;
- q[a].ans = q[a].y - q[a].x;
- }
- if(maxx<q[a].cnt)
- {
- maxx = q[a].cnt;
- }
- }
- sort(q,q+N,cmp);
- printf("%d %d\n",q[0].x,q[0].y);
- }
- return 0;
- }
B. Amr and The Large Array(Codeforces Round #312 (Div. 2)+找出现次数最多且区间最小)的更多相关文章
- 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/contes ...
- Codeforces Round #312 (Div. 2) ABC题解
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...
- Codeforces Round #312 (Div. 2)
好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...
- Codeforces Round #312 (Div. 2) B.Amr and The Large Array
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. ...
- Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...
- Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力
C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/ ...
- Codeforces Round #312 (Div. 2) C.Amr and Chemistry
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experime ...
- C. Amr and Chemistry(Codeforces Round #312 (Div. 2) 二进制+暴力)
C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 1042d//Petya and Array// Codeforces Round #510 (Div. 2)
题意:给出一个数组,求其中和小于t的区间数. 先计算前缀和数组sum[i].对当前的sum[i],查询树状数组中有几个比(sum[i]-t)大的数,那么用sum[i]减它就是一个合法区间.再将当前的s ...
随机推荐
- js模拟支付宝发送短信验证码&&&&短信倒计时
html <div class="pwdContent"> <div class="pwdBox"></div> <d ...
- flatpickr插件的使用
flatpickr功能强大的日期时间选择器插件 日期格式化 <input class=flatpickr data-date-format="d-m-Y"> <i ...
- Linux终端以及bash
目 录 第1章 Linux系统终端概述 1 1.1 图形化 1 1.2 字符终端 1 1.3 who和w 1 1.3.1 who 1 1.3.2 w 1 1.3.3 ...
- PCB中贴片元器件的引脚规范(allegro)
表贴的芯片一个引脚焊盘的宽度: 当芯片引脚间的间距>=26mil时,计算公式是(脚宽度+8mil) 当芯片引脚的间距<26mil时,计算公式是(引脚间距/2+1) 表贴的芯片一个引脚焊盘的 ...
- 判断List集合为空
package org.springframework.util; CollectionUtils.isEmpty(list)
- 《C语言程序设计(第四版)》阅读心得(四 文件操作)
第10章 对文件的输入输出 函数名 调用形式 功能 fopen fopen(“a1”,”r”); 打开一个文件 fclose fclose( fp ); 关闭数据文件 fgetc fgetc( fp ...
- 防火墙内设置FileZilla Server注意事项
开启了Windows下的防火墙,如何设置FileZilla Server 相关选项,能在服务器端只开启21,23端口就可以正常连接使用 方法/步骤 1. 开启windows防火墙,同时 ...
- URAL 1297 求最长回文字符串
有种简单的方法,数组从左到右扫一遍,每次以当前的点为中心,只要左右相等就往左右走,这算出来的回文字符串是奇数长度的 还有偶数长度的回文字符串就是以当前扫到的点和它左边的点作为中心,然后往左右扫 这是O ...
- 舒适的路线(codevs 1001)
题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N(1<N≤500)个景点(编号为1,2,3,…,N),这些景点被M(0<M≤ ...
- msp430入门学习00
在TI官网上找到MSP430的程序例程.数据手册.使用指南等文件.以MSP430F169为例,步骤如下: 1)进入ti官网:http://www.ti.com.cn/ 或者http://www.ti. ...