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 ...
随机推荐
- 小记------查看‘阿里云机器’yarn 日志
通过ip:8088 页面 复制正在运行的application ID 在linux客户端执行 xshell yarn logs -applicationId application_155869 ...
- Servlet概念及与Jsp的区别
一.Servlet概念 Servlet是在服务器上运行的小程序.一个Servlet就是一个Java类,并且可以通过”请求-响应”编程模型来访问这个驻留在服务器内存里的Servlet程序 二.Servl ...
- HDU1846 Brave Game 题解
题面 本题是一道有向图博弈问题: 该题便是著名的巴什博弈: 我们可以发现,当n=0的时候后手必胜(设其为P态),n=1~m这几种状态由于先手可以一次全部取完导致先手必胜(设其为N态). 接着当n=m+ ...
- 手写数字识别 卷积神经网络 Pytorch框架实现
MNIST 手写数字识别 卷积神经网络 Pytorch框架 谨此纪念刚入门的我在卷积神经网络上面的摸爬滚打 说明 下面代码是使用pytorch来实现的LeNet,可以正常运行测试,自己添加了一些注释, ...
- [BZOJ2964]Boss单挑战
题目描述 某\(RPG\)游戏中,最后一战是主角单挑\(Boss\),将其简化后如下: 主角的气血值上限为\(HP\),魔法值上限为\(MP\),愤怒值上限为\(SP\):\(Boss\)仅有气血值, ...
- P1106 删数问题
展开 题目描述 键盘输入一个高精度的正整数NN(不超过250250位) ,去掉其中任意kk个数字后剩下的数字按原左右次序将组成一个新的正整数.编程对给定的NN和kk,寻找一种方案使得剩下的数字组成的新 ...
- git推送新项目到github
1.首先在github上新建一个裸仓库 得到新仓库地址 2.打开本地要添加项目的目录,右键选择git bash,执行命令 (1)git init (2)git remote add origin ht ...
- python pycharm 注册码
D87IQPUU3Q-eyJsaWNlbnNlSWQiOiJEODdJUVBVVTNRIiwibGljZW5zZWVOYW1lIjoiTnNzIEltIiwiYXNzaWduZWVOYW1lIjoiI ...
- Ubuntu下火狐浏览器播放视频出现解码问题
问题描述 点击视频播放按钮,视频不会出现缓冲条,也没任何提示,视频界面就一直是黑屏的状态.右键该视频界面,选择检查元素,点击控制台,发现如下问题: The video on this page can ...
- 将ShellCode注入进程内存
内存注入ShellCode的优势就在于被发现的概率极低,甚至可以被忽略,这是因为ShellCode被注入到进程内存中时,其并没有与之对应的硬盘文件,从而难以在磁盘中取证,但也存在一个弊端由于内存是易失 ...