尺取,写起来有点麻烦

枚举左端点,然后找到右端点,,使得区间[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 尺取的更多相关文章

  1. Gym 100703I---Endeavor for perfection(尺取)

    题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...

  2. 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 ...

  3. hdu 4123 Bob’s Race 树的直径+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  4. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  5. poj2566尺取变形

    Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...

  6. poj2100还是尺取

    King George has recently decided that he would like to have a new design for the royal graveyard. Th ...

  7. hdu 6231 -- K-th Number(二分+尺取)

    题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...

  8. Codeforces 939E Maximize! (三分 || 尺取)

    <题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...

  9. HDU 5178 pairs【二分】||【尺取】

    <题目链接> 题目大意: 给定一个整数序列,求出绝对值小于等于k的有序对个数. 解题分析: $O(nlong(n))$的二分很好写,这里就不解释了.本题尺取$O(n)$也能做,并且效率很不 ...

随机推荐

  1. sql-connectionStrings

    <connectionStrings> <add name="ClassReservatConnectionString" connectionString=&q ...

  2. Javascript - ExtJs - 整合百度文章编辑器

    ExtJs - 整合百度文章编辑器(ExtJs UEditor) 第一步:去官网下载最新版本的UEditor,UEditor下载. 第二步:在编辑器根目录创建一个Extjs-Editor.js,录入以 ...

  3. QR 编码原理(二)

    编码就是把常见的数字.字符等转换成QR码的方法.说具体的编码之前,先说一下QR码的最大容量问题. 一.最大容量 QR码的最大容量取决于选择的版本.纠错级别和编码模式(Mode:数字.字符.多字节字符等 ...

  4. ipconfig命令查ip的时候给别人看有危险吗

    知识源:Unit 4: Networking 1 4.1 Networking 1 The Routing of a Packet  网址:https://www.baidu.com/link?url ...

  5. [Kubernetes]CentOS7部署Kubernetes集群

    环境介绍及安装前准备 三台机器,用于部署k8s的运行环境: 节点 ip Master 192.168.243.138 Node1 192.168.243.139 Node2 192.168.243.1 ...

  6. codevs 1082 线段树练习3 (线段树)

    题目: 题目描述 Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[a,b]的数的和. 输入描述 Input Description 第一行一个正整数 ...

  7. IPC$横向渗透代码实现

    思路 IPC$横向渗透的方法,也是病毒常用的扩散方法. 1.建立连接 2.复制文件到共享中C$.D$.E$.F$ 3.获取服务器的时间 3.设定计划任务按时间执行 用到的Windows API 建立网 ...

  8. 使用html2canvas生成一张图片

    注意事项: 1.图片生成问题,生成图片测试机正常传到正式机,无法生成!!====>>原因是正式机中,使用的是CDN加载,导致图片跨域,而canvas不支持图片跨域!!!==>> ...

  9. linux批量替换文件内容3种方法(perl,sed,shell)

    方法1:perl   这两天在构建一个应用的使用用到了maven,由于project很大,足足有700多个 pom.xml文件,更郁闷的是在很多pom.xml文件里都单独指定了资源库的url,我需要把 ...

  10. 训练报告 (2014-2015) 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest

    Solved A Gym 100488A Yet Another Goat in the Garden   B Gym 100488B Impossible to Guess Solved C Gym ...