题意:给定一个数组,求最小的字数组使得数组里存在至少一对重复元素

题解:每个点求出他的后继在哪,然后每次贪心就这个点到他的后继为一个子数组,求出最小的就是答案

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#define ll long long
using namespace std;
int T,n,ans;
int a[],nxt[],hd[];
int main()
{
scanf("%d",&T);
while(T--)
{
for(int i=;i<=n;i++)hd[i]=nxt[i]=;
scanf("%d",&n);
for(int i=;i<=n;i++){scanf("%d",&a[i]);nxt[i]=hd[a[i]];hd[a[i]]=i;}
ans=1e9;
for(int i=;i<=n;i++)if(nxt[i])ans=min(ans,i-nxt[i]+);
printf(ans==1e9?"-1\n":"%d\n",ans);
}
return ;
}

【CF1257C】Dominated Subarray【贪心】的更多相关文章

  1. Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题

    C. Dominated Subarray Let's call an array

  2. Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray

    Let's call an array tt dominated by value vv in the next situation. At first, array tt should have a ...

  3. C.Dominated Subarray

    题目:受主导的子序列 题意:序列t至少有2个元素,我们称序列t被数字出现次数最多的元素v主导,且出现次数最多的元素必须是唯一的 你被给予了序列a1, a2, ..., an,计算它的最短受主导子序列, ...

  4. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  5. Educational Codeforces Round 76 (Rated for Div. 2)

    传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...

  6. LeetCode--Best Time to Buy and Sell Stock (贪心策略 or 动态规划)

    Best Time to Buy and Sell Stock Total Accepted: 14044 Total Submissions: 45572My Submissions Say you ...

  7. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  8. [LeetCode]题53:Maximum Subarray

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...

  9. 152. Maximum Product Subarray最大乘积子数组/是否连续

    [抄题]: Given an integer array nums, find the contiguous subarray within an array (containing at least ...

随机推荐

  1. Delphi XE2 之 FireMonkey 入门(14) - 滤镜: 概览

    相关单元: FMX.Filter FMX.FilterCatBlur FMX.FilterCatGeometry FMX.FilterCatTransition FMX_FilterCatColor ...

  2. fillna()函数

    method:  pad/ffill:用前一个非缺失值去填充该缺失值,用左边的非缺失值去填充该缺失值          backfill/bfill:用下一个非缺失值填充该缺失值,用右边的非缺失值去填 ...

  3. charles_01_打断点修改接口请求&返回数据

    前言 测试过程中,为了模拟某场景测试,经常需要修改接口请求或者返回数据.可通过抓包工具打断点,实现模拟测试场景.常用的抓包工具charles和fiddler均可打断点mock数据.由于小编安装了cha ...

  4. IE浏览器下用JS创建文件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. mysql数据库监控工具-MONyog的配置和基本使用项

    测试数据传输前,研发要求需要监控10万,50万,100万数量级的数据在传输过程数据库服务器的资源消耗情况,因为数据传输服务是定时任务执行,配置10秒中一次,一次处理500条,处理完10万数据可能要半个 ...

  6. ./configure 配置文件时出错checking for g++... no

    checking for g++... no checking for c++... no checking for gpp... no checking for aCC... no 缺少C++编译器 ...

  7. HNUSTOJ-1689 送外卖(TSP问题)

    1698: 送外卖 时间限制: 1 Sec  内存限制: 128 MB 提交: 115  解决: 24 [提交][状态][讨论版] 题目描述 在美团和饿了么大行其道的今天,囊中羞涩的小周和小美,也随大 ...

  8. [AGC005F] Many Easy Problems

    link 题意简述 给定一颗无根树,对于所有大小为 $i$ 的点集,求出能够包含它的所有联通块之和,定义为 $f_i$ ,答案对 $924844033$ 取模. $n\leq 2\times 10^5 ...

  9. Rabbitmq 运维

    Rabbitmq 运维 一.安装: 安装ncurses wget http://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz tar zxf ncurses-6 ...

  10. bootstrap复习

    菜单 <div class="row">下拉菜单/分裂菜单</div> <div class="dropdown btn-group&quo ...