B. Uniqueness
给定一个序列,要求删除一段连续子段,满足删掉子段后每个元素唯一
求最小子段长度
枚举起点,二分子段长度
记得先sort 再unique
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define si signed
#define endl '\n'
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=1;i<=n;i++)scanf("%I64d",&A[i]);
#define P pair<int,int>
#define fi first
#define se second
#define ot(x) cout<<x<<'\n';
#define maxn 10000+5
int A[maxn];
int n,t,x,y,a,b;
vector<int> v;
bool check(int l,int mid)
{
v.clear();
for(int i=;i<=n;i++){
if(i<l)v.push_back(A[i]);
else if(i>mid)v.push_back(A[i]);
else i=mid;
}
sort(v.begin(),v.end());
int n=unique(v.begin(),v.end())-v.begin();
return n==v.size();
}
signed main()
{
sc(n);
for(int i=;i<=n;i++){
sc(A[i]);
v.push_back(A[i]);
}
sort(v.begin(),v.end());
int x=unique(v.begin(),v.end())-v.begin(); if(x==n){
cout<<<<'\n';
return ;
}
int len=n;
for(int i=;i<=n;i++){
int l=i,r=i+len-;
if(!check(i,r))continue;
while(l+<r){
int mid=(l+r)/;
if(check(i,mid)){
r=mid;
}else l=mid+;
}
if(check(i,l)){
len=min(l-i+,len);
}else if(check(i,r)){
len=min(r-i+,len);
}
}
cout<<len<<'\n';
}
B. Uniqueness的更多相关文章
- ruby on rails validates uniqueness
最近在处理一个小功能,每个元素可以有多个图片,每个图片的name表示了它是背景图还是海报图, 需要对每个元素的图片name做一个唯一性验证,一个元素不能添加两个海报图, 需要使用的是validates ...
- PowerDesigner Constraint name uniqueness 问题处理(转载)
使用PowerDesigner生成数据库脚本时报 Constraint name uniqueness 错误: 双击每行错误,发现外键引用的名字有重复的: 惯性去网上找解决办法,找到的主要是两个方法: ...
- Theorems for existence and uniqueness of variational problem
Introduction Among simulation engineers, it is well accepted that the solution of a PDE can be envis ...
- PowerDesigner Constraint name uniqueness 错误
使用PowerDesigner生成数据库脚本时报 Constraint name uniqueness 错误: 双击每行错误,发现外键引用的名字有重复的: 惯性去网上找解决办法,找到的主要是两个方法: ...
- PowerDesigner 同名问题解决 Entity Attribute name uniqueness
选择"Tools -> Model Options"后 "Allow reuse"复选框,建议把这个钩也去掉 Tool->check model.. ...
- CodeForces 297C Splitting the Uniqueness (脑补构造题)
题意 Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指 ...
- Codeforces 297C. Splitting the Uniqueness
C. Splitting the Uniqueness time limit per test:1 second memory limit per test:256 megabytes input:s ...
- B. Uniqueness(尺取)
B. Uniqueness time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- B. Uniqueness 删除最小区间内的元素使得剩余元素唯一
B. Uniqueness time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- IIS服务搭建 试图加载格式不正确的程序
1.基础步骤 https://jingyan.baidu.com/article/fedf073770f23335ac8977b1.html 2.错误解决 试图加载格式不正确的程序 解决:在IIS ...
- 拼音检查python
#coding=utf-8 #!/usr/bin/python import sys, re, collections #读入文件 def read_file(filename): try: fp = ...
- GitHub 上有哪些优秀的 Python 爬虫项目?
目录 GitHub 上有哪些优秀的 Python 爬虫项目? 大型爬虫项目: 实用型爬虫项目: 其它有趣的Python爬虫小项目: GitHub 上有哪些优秀的 Python 爬虫项目? 大型爬虫项目 ...
- [..net core]4.入口,Main方法 及InProcess
通常控件台程序都有一个main方法, public class Program { public static void Main(string[] args) { CreateWebHostBuil ...
- LeetCode题目(python)
1.给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中同样 ...
- 090、ELK完成部署和使用 (2019-05-13 周二)
参考https://www.cnblogs.com/CloudMan6/p/7787870.html 上节我们已经部署了容器化的ELK,本节我们学习如何将日志导入ELK并进行图形化展示. 几乎 ...
- hadoop面试复习笔记(1)
0.Mappereduce采用的是Master/Slaves模型 1.Hadoop是一个开源软件框架,支持支持大数据集的存储和处理.Apache Hadoop是存储和处理大数据的解决方案你是因为: ( ...
- vue中获取本地ip
一.目的 获取当前访问的ip地址 二.思路 通过使用搜狐的api获取访问ip 三.操作步骤 1.在index.html中添加 <script src="http://pv.sohu.c ...
- git 计算commit
转自:https://www.cnblogs.com/jwentest/p/8186712.html#!/bin/bash f1="$1*" f2="$2*" ...
- 经典Spring入门基础教程详解
经典Spring入门基础教程详解 https://pan.baidu.com/s/1c016cI#list/path=%2Fsharelink2319398594-201713320584085%2F ...