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 ...
随机推荐
- ThinkPHP小知识点
ThinkPHP模版中时间戳转换为时间 {$vo.data|date='Y-m-d',###} thinkphp字符截取函数msubstr() ThinkPHP有一个内置字符截取函数mb_substr ...
- ROS + Caffe 机器人操作系统框架和深度学习框架笔记 (機器人控制與人工智能)
ROS + Caffe,这里以环境中物体识别为示例,机器人怎么知道环境里面有什么呢? [0.0567392 - n03376595 folding chair][0.0566773 - n040999 ...
- 数据库中INFORMATION_SCHEMA的说明及使用
第一个查询看看库里有多少个表,表名等select * from INFORMATION_SCHEMA.TABLES information_schema这张数据表保存了MySQL服务器所有数据库的信息 ...
- 利用Requests库写爬虫
基本Get请求: #-*- coding:utf-8 -*- import requests url = 'http://www.baidu.com' r = requests.get(url) pr ...
- IE源代码摘抄,基于泄漏的IE5.0(持续更新)
下载了一份很久以前泄漏的IE5.0的源代码,虽然已经是很古远的版本了.但是通过调试现有版本浏览器与查看源代码,发现关键部分的差距并不是很大,代码很有参考意义.这里把重要的函数.数据结构摘抄出来以备参考 ...
- input文本框 输入限制三则
其一,只允许输入数字和小数点. <input onKeypress="return (/[\d.]/.test(String.fromCharCode(event.keyCode))) ...
- 【洛谷】P2000 拯救世界
题解 小迪的blog : https://www.cnblogs.com/RabbitHu/p/9178645.html 请大家点推荐并在sigongzi的评论下面点支持谢谢! 掌握了小迪生成函数的有 ...
- CentOS7.5安装cairo-dock,比mac托盘还美
1.下载安装nux-desktop 到http://li.nux.ro/download/nux/dextop/el7/x86_64/找到nux-dextop-release-xxxx.nux.noa ...
- django视图函数中 应用装饰器
from django.shortcuts import render, redirect, HttpResponse from .forms import LoginForm, Registrati ...
- Bootstrap--响应式导航条布局
<!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...