【Codeforces Round #451 (Div. 2) D】Alarm Clock
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
尺取法+二分。
类似滑动窗口。
即左端点为l,右端点为r.
维护a[r]-a[l]+1总是小于等于m的就好。
(大于m就右移左端点)
然后看看里面的数字个数是不是小于k;
不是的话让l..r中最右边那个数字删掉就好。
->链表优化一下即可。
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
sort(a+1,a+1+n);
L[i] = i-1;R[i] = i+1;
一开始l = 1,r = 0,now=0;
然后for (int i = 1;i <= n;i++){
r = i;
now++;
while(l <= r && a[r]-a[l]+1>m){
now--;
l=R[l];
}
if(now >=k){
for (int j = i,k = 1;k<=now-k+1;k++,j=L[j]){
delete(j);
ans++;
}
}
now = k-1;
}
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n,m,k;
int a[N+10],L[N+10],R[N+10],ans;
void Delete(int pos){
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m >> k;
for (int i = 1;i <= n;i++) cin >> a[i];
sort(a+1,a+1+n);
for (int i = 1;i <= n;i++)
L[i] = i-1,R[i] = i+1;
R[0] = 1,L[n+1] = n;
int l = 1,r = 0,now = 0;
for (int i = 1;i <= n;i++){
r = i;
now++;
while(l <= r && a[r]-a[l]+1>m){
if (a[l]!=0) now--;
l=R[l];
}
if(now >=k){
a[r] = 0;
int ll = L[r],rr = R[r];
R[ll] = rr;
L[rr] = ll;
now--;
ans++;
}
}
cout << ans << endl;
return 0;
}
【Codeforces Round #451 (Div. 2) D】Alarm Clock的更多相关文章
- 【Codeforces Round #451 (Div. 2) A】Rounding
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟 [代码] /* 1.Shoud it use long long ? 2.Have you ever test several ...
- 【Codeforces Round #451 (Div. 2) B】Proper Nutrition
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以直接一层循环枚举. 也可以像我这样用一个数组来存y*b有哪些. 当然.感觉这样做写麻烦了.. [代码] /* 1.Shoud i ...
- 【Codeforces Round #451 (Div. 2) C】Phone Numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map<string,vector > dic;模拟就好. 后缀.翻转一下就变成前缀了. 两重循环剔除这种情况不输出就 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
随机推荐
- 《Android编程权威指南》PhotoGallery应用梳理
PhotoGalley是<Android编程权威指南>书中另外一个重要的应用.
- msiexec
msiexec: runCmd = new String[]{ "msiexec", "/i", exeName, "/quiet", &q ...
- Restricted Boltzmann Machines
转自:http://deeplearning.net/tutorial/rbm.html http://blog.csdn.net/mytestmy/article/details/9150213 能 ...
- 日天的终生大事(dp)
日天的终生大事 题目描述 日天学长向妹子表白了,妹子说:“日天你那么聪明,回答我一个问题就答应你.你告诉我,L位K进制数有多少个?”日天表示这个问题太简单了,要求提高难度.妹子想了想说:“那么我增加一 ...
- centos 5的yum源无法使用的解决方法( 转载)
由于centos 5 已经停更.于是导致yum源也不能用了. 例如安装screen的时候提示 Determining fastest mirrors* base: denver.gaminghost. ...
- 23种JavaScript设计模式
原文链接:https://boostlog.io/@sonuton/23-javascript-design-patterns-5adb006847018500491f3f7f 转自: https:/ ...
- 原生js模拟jquery中的addClass和removeClass方法
js代码: //添加类 function addClass(obj,className) { if(obj.className == '') { //如果没有class obj.className = ...
- SpringBoot常用注解的介绍及使用 - 转载
常用注解 @springBootApplication 系统启动类注解,此注解是个组合注解,包括了:@SpringBootConfiguration,@EnableAutoConfiguration, ...
- 洛谷 P1244 青蛙过河
P1244 青蛙过河 题目描述 有一条河,左边一个石墩(A区)上有编号为1,2,3,4,…,n的n只青蛙,河中有k个荷叶(C区),还有h个石墩(D区),右边有一个石墩(B区),如下图所示.n只青蛙要过 ...
- cogs 1755. 爱上捉迷藏
1755. 爱上捉迷藏 ☆ 输入文件:kadun.in 输出文件:kadun.out 简单对比时间限制:0.001 s 内存限制:2 MB [背景] 乃们都玩过赛尔号吧……,那有木有玩 ...