cf1121d 尺取
尺取,写起来有点麻烦
枚举左端点,然后找到右端点,,使得区间[l,r]里各种颜色花朵的数量满足b数组中各种花朵的数量,然后再judge区间[l,r]截取出后能否可以供剩下的n-1个人做花环
/*
给定序列A,分成n段,每段k个,
然后删掉A中的一些,但任要能组成n段,使得A中的一段包含序列B中的所有元素
如果可以输出删掉的元素,否则输出-1
*/
#include<bits/stdc++.h>
using namespace std;
#define maxn 500005
int m,k,n,s,a[maxn],b[maxn],c[maxn];
int tot[maxn],cnt[maxn];//tot[i]表示第i种颜色需要的数量
int l,r,sum,Max,all;
int judge(int l,int r){//判断除去l,r是否可行
int tmp1=l-,tmp2=m-r;
if(tmp1/k+tmp2/k+>=n)return ;
return ;
}
void add(int i){
if(cnt[a[i]]==)return;
tot[a[i]]++;
if(tot[a[i]]==cnt[a[i]])sum++;
}
void del(int i){
if(cnt[a[i]]==)return;
tot[a[i]]--;
if(tot[a[i]]==cnt[a[i]]-)sum--;
} int main(){
cin>>m>>k>>n>>s;
for(int i=;i<=m;i++)cin>>a[i],Max=max(Max,a[i]);
for(int i=;i<=s;i++)cin>>b[i],Max=max(Max,b[i]);
for(int i=;i<=s;i++)cnt[b[i]]++; l=,r=k;sum=;
for(int i=;i<=Max;i++)
if(cnt[i]!=)all++;
for(int i=l;i<=k;i++)
add(i); while(){
if(sum==all){
if(judge(l,r)){//可行
vector<int>v;
v.clear();
int tmp=r-l+;
for(int i=l;i<=r;i++){
if(cnt[a[i]]> || tmp==k)
cnt[a[i]]--;
else v.push_back(i),tmp--;
}
printf("%d\n",v.size());
for(int i=;i<v.size();i++)
printf("%d ",v[i]);
return ;
}
del(l);l++;
} while(sum<all || l+k->r){
r++;
if(r>m)break;
add(r);
}
if(r>m)break;
}
puts("-1");
}
cf1121d 尺取的更多相关文章
- Gym 100703I---Endeavor for perfection(尺取)
题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...
- NOJ 1072 The longest same color grid(尺取)
Problem 1072: The longest same color grid Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit in ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- poj2566尺取变形
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- poj2100还是尺取
King George has recently decided that he would like to have a new design for the royal graveyard. Th ...
- hdu 6231 -- K-th Number(二分+尺取)
题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...
- Codeforces 939E Maximize! (三分 || 尺取)
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...
- HDU 5178 pairs【二分】||【尺取】
<题目链接> 题目大意: 给定一个整数序列,求出绝对值小于等于k的有序对个数. 解题分析: $O(nlong(n))$的二分很好写,这里就不解释了.本题尺取$O(n)$也能做,并且效率很不 ...
随机推荐
- __call__
object.__call__(self[, args...]) Called when the instance is “called” as a function; if this method ...
- 论文笔记系列-Speeding Up Automatic Hyperparameter Optimization of Deep Neural Networks by Extrapolation of Learning Curves
I. 背景介绍 1. 学习曲线(Learning Curve) 我们都知道在手工调试模型的参数的时候,我们并不会每次都等到模型迭代完后再修改超参数,而是待模型训练了一定的epoch次数后,通过观察学习 ...
- Curator实现分布式锁
分布式锁的应用 分布式锁服务宕机, ZooKeeper 一般是以集群部署, 如果出现 ZooKeeper 宕机, 那么只要当前正常的服务器超过集群的半数, 依然可以正常提供服务 持有锁资源服务器宕机, ...
- MyBatis-进阶2
typeHandler typeHandler有什么用? 你可以重写类型处理器或创建你自己的类型处理器来处理不支持的或非标准的类型. 具体做法为:实现 org.apache.ibatis.type.T ...
- SpringSecurity实现图形验证码功能
⒈封装验证码类 package cn.coreqi.security.validate; import java.awt.image.BufferedImage; import java.time.L ...
- C++ 11 snippets , 2
<1>auto ,initializer_list<T>,auto指向函数指针的简易,和typdef 定义的类型执行函数指针有多复杂. #include <iostrea ...
- 【转】简单谈谈python的反射机制
[转]简单谈谈python的反射机制 对编程语言比较熟悉的朋友,应该知道“反射”这个机制.Python作为一门动态语言,当然不会缺少这一重要功能.然而,在网络上却很少见到有详细或者深刻的剖析论文.下面 ...
- Linux系统启动那些事—基于Linux 3.10内核【转】
转自:https://blog.csdn.net/shichaog/article/details/40218763 Linux系统启动那些事—基于Linux 3.10内核 csdn 我的空间的下载地 ...
- Centos6.8下SVN安装
1.yum -y install subversion svnserve --version 查看版本 2.@创建SVN仓库目录 mkdir -p /data/svn/repositories 3.@ ...
- gnutls-3.5.18 static building for windows
gnutls-3.5.18 static building for windows Required libraries:1. libnettle 2. gmplib Optional librari ...