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[]; int main()
{
for(int i=;i<=;i++)
a[i].x=,a[i].y=-,a[i].z=;
int n;
scanf("%d",&n);
int ans=;
for(int i=;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=,ans2=;
for(int i=;i<=;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;
}
Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力的更多相关文章
- 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 #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 ...
- Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees 暴力
A. Lala Land and Apple Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/cont ...
- B. Amr and The Large Array(Codeforces Round #312 (Div. 2)+找出现次数最多且区间最小)
B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...
- 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)(前者是位置,后者是价 ...
- 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 Round #312 (Div. 2) A.Lala Land and Apple Trees
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. ...
随机推荐
- stitch image app (Qt)
result how to use? source code http://7qnct6.com1.z0.glb.clouddn.com/dropSelect.rar
- ASP.NET Cookie对象到底是毛啊?(简单小例子)
记得刚接触asp.net的时候,就被几个概念搞的头痛不已,比如Request,Response,Session和Cookie.然后还各种在搜索引擎搜,各种问同事的,但是结果就是自己还是很懵的节奏. 那 ...
- 迭代的模块itertools
itertools模块提供的全部是处理迭代功能的函数,他们的返回值不是list,而是迭代对象,只有在for循环的时候才会真正去计算. 使用迭代器的好处是在循环的时候才去取值,而直接返回值为list的结 ...
- Epic - Seed Number
Find the seed of a number. Eg : 1716 = 143*1*4*3 =1716 so 143 is the seed of 1716. find all possible ...
- Quartz与Spring集成
关于Quartz的基本知识,这里就不再多说,可以参考Quartz的example. 这里主要要说的是,个人在Quartz和Spring集成的过程中,遇到的问题和个人理解. 首先来说说个人的理解: 1. ...
- Android Activity学习笔记(一)
Activity为Android应用的四大组件之一,提供界面来与用户完成交互等操作.其中Activity的生命周期的知识这里做个笔记. Activity的生命周期由以下几个部分组成: 1.onCrea ...
- linux命令 screen的简单使用
在远程命令行下某些长时间的操作,一旦网络出现故障,后果可能会很严重,在这种情况下可以使用screen命令来解决.screen可以创建一个session,在不小心断开以后还可以继续恢复session保存 ...
- 云计算分布式大数据Hadoop实战高手之路第七讲Hadoop图文训练课程:通过HDFS的心跳来测试replication具体的工作机制和流程
这一讲主要深入使用HDFS命令行工具操作Hadoop分布式集群,主要是通过实验的配置hdfs-site.xml文件的心跳来测试replication具体的工作和流程. 通过HDFS的心跳来测试repl ...
- 手势冲突UIPanGestureRecognizer 和UIPinchGestureRecognizer
当同时使用pan和pin手势时假如冲突,需要加入下面方法 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shou ...
- php--opp--2.什么是类,什么是对象,类和对象这间的关系
类的概念:类是具有相同属性和服务的一组对象的集合.它为属于该类的所有对象提供了统一的抽象描述,其内部包括属性和服务两个主要部分.在面向对象的编程语言中,类是一个独立的程序单位,它应该有一个类名并包括属 ...