codeforces 558B Amr and The Large Array-yy
题意:有一个数组。如今要削减它的尺寸。数组中同样元素的个数的最大值为数组的魅力值,要求削减后魅力值不能降低,同一时候要尽可能的把尺寸减到最小
分析:水题,主要是不要想复杂了。还有就是沉下心来做
代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#define INF 1000000007
#define max(a,b) a>b?a:b
using namespace std;
int n,a[100010];
int tot[1000010];
int l[1000010],r[1000010];
int main()
{
while(cin>>n){
memset(tot,0,sizeof(tot));
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
int mx=-1;
for(int i=1;i<=n;i++){
cin>>a[i];
if(tot[a[i]]==0) l[a[i]]=i,r[a[i]]=i;
else r[a[i]]=i;
tot[a[i]]++;
mx=max(mx,tot[a[i]]);
}
int mi=INF;
int ans;
for(int i=1;i<=n;i++){
if(tot[a[i]]==mx){
int tmp=r[a[i]]-l[a[i]];
if(mi>tmp){
mi=tmp;
ans=a[i];
}
}
}
cout<<l[ans]<<" "<<r[ans]<<endl;
}
}
codeforces 558B Amr and The Large Array-yy的更多相关文章
- Codeforces 558B Amr and The Large Array
B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...
- codeforces 558B. Amr and The Large Array 解题报告
题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...
- codeforces 558B B. Amr and The Large Array(水题)
题目链接: B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes in ...
- 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 ...
- 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 ...
- CF 558B(Amr and The Large Array-计数)
B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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 558B
Description Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make ...
随机推荐
- putIfAbsent
public static HashSet<Long> getOrInitHashMapCacheValue(Long mId){ // HashSet<Long> set = ...
- Java字符串常见实例与函数
字符串比较 字符串函数 compareTo (string) ,compareToIgnoreCase(String) 及 compareTo(object string) 来比较两个字符串,并返回字 ...
- 关于RundownProtect到底是什么东西
RundownProtect这个字段相信只要是读过WRK源码的都会看过这个东西,这个字段在进程和线程的结构中都存在.最典型的例子就是对进程要进行什么操作的时候会先引用这个字段进行加保护,等操作结束后再 ...
- 安装部署Apache Hadoop (本地模式和伪分布式)
本节内容: Hadoop版本 安装部署Hadoop 一.Hadoop版本 1. Hadoop版本种类 目前Hadoop发行版非常多,有华为发行版.Intel发行版.Cloudera发行版(CDH)等, ...
- 程序设计实习MOOC / 程序设计与算法(二)第二周测验(2018春季)
递归算法: 1:全排列 总时间限制: 1000ms 内存限制: 65536kB 描述 给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列. 我们假设对于小写字母有'a' < ' ...
- Linux 下开发环境的搭建(软件安装)
一.Centos6.5下安装JDK 步骤1: 查看现有安装的JDK版本 rpm –qa | grep -i java 步骤2: 卸载已有软件 rpm -e --nodeps java-1.7.0-op ...
- 老的API实现WordCount
使用Hadoop版本0.x实现单词统计 package old; import java.io.IOException; import java.net.URI; import java.util.I ...
- Ruby windows7安装配置(最新版本)
1.下载最新版本的rubyinstaller并安装http://rubyinstaller.org/downloads/ 如下图所示设置路径,我安装时将所有选项都打够了,免除了后面需要什么配置麻烦. ...
- iOS 9应用开发教程之创建iOS 9项目与模拟器介绍
iOS 9应用开发教程之创建iOS 9项目与模拟器介绍 编写第一个iOS 9应用 本节将以一个iOS 9应用程序为例,为开发者讲解如何使用Xcode 7.0去创建项目,以及iOS模拟器的一些功能.编辑 ...
- 1011 World Cup Betting (20)(20 point(s))
problem With the 2010 FIFA World Cup running, football fans the world over were becoming increasingl ...