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 ...
随机推荐
- Git push将本地版本库的分支推送到远程服务器上对应的分支
在使用git commit命令将修改从暂存区提交到本地版本库后,只剩下最后一步将本地版本库的分支推送到远程服务器上对应的分支了,如果不清楚版本库的构成,可以查看我的另一篇,git 仓库的基本结构. g ...
- Selenium_多线程执行测试用例
多线程执行测试用例 这里以百度搜索为例,通过不同的浏览器来启动不同的线程. #!/usr/bin/env python # _*_ coding:utf-8 _*_ __author__ = 'Yin ...
- Python学习笔记:个税起征点上调至5000,算一算少交多少税?
一.旧税率表与新税率表比较 以前起征点是3500,2018年10月1日起起征点正式修改为5000,下面我们用Python来分别计算新旧个人所得税分别为多少? 二.旧的个人所得税 import sys ...
- python对象学习
python对象的介绍 python使用对象模型来存储数据,构造任何类型的值都是一个对象,尽管python被当成面向对象的编程语言,但是完全编写不使用任何类和实例的脚本.所有的python对象都拥有三 ...
- 浅析redux
一 redux 思想 首先,每一个webApp有且只有一个state tree,为方便管理和跟踪state的变化,也为了减少混乱,redux只允许通过发送(dispatch)action的方式来改变s ...
- SSIS 学习之旅 FTP文件传输-FTP任务
这一章主要讲解一下FTP控件. 设计: 通过Demon库的Users表数据生成CSV文件. 生成后的CSV文件抛送到FTP指定目录下. 其他控件的使用这里就不做详细讲解了.大家如果有不懂得可以 ...
- spring boot在控制台输出彩色日志
阅读org.springframework.boot.context.config.AnsiOutputApplicationListener 源码发现,通过向JVM传递参数,可以在控制台打印彩色日志 ...
- codeforces 603 A
题目大意:给你一个0,1串, 你可以反转一段连续的区间,问你最长的合法子串是多长, 合法字串相邻的两个不能相同. 思路:dp[ i ][ k ][ j ] 表示到第 i 个字符, 处于k这种状态, k ...
- 8-10 Coping Books uva714
题意:把一个包含m个正整数的序列划分为k个 1<=k<=m<=500的非空连续子序列 使得每个正整数恰好属于一个序列 设第i个序列的各个数之和为 Si 你的任务是让所有的 ...
- Git错误提示之:fatal: Not a git repository (or any of the parent directories): .git
产生原因:一般是没有初始化git本地版本管理仓库,所以无法执行git命令 解决方法:操作之前执行以下命令行: git init 然后执行一下git status查看状态信息,good,问题解决.