【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两种颜色的格子; 让你在这个格子 ...
随机推荐
- 10010序列检测器的三段式状态机实现(verilog)
序列检测器是时序数字电路设计中经典的教学范例,夏宇闻的<verilog数字系统设计教程>一书中有这个例子,用verilog设计一个“10010”序列的检测器.看完后我觉得F和G两个状态多余 ...
- LSTM入门学习——本质上就是比RNN的隐藏层公式稍微复杂了一点点而已
LSTM入门学习 摘自:http://blog.csdn.net/hjimce/article/details/51234311 下面先给出LSTM的网络结构图: 看到网络结构图好像很复杂的样子,其实 ...
- Day2代码
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #defi ...
- java.beans.PropertyChangeListener
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.P ...
- SpringBoot常用注解的介绍及使用 - 转载
常用注解 @springBootApplication 系统启动类注解,此注解是个组合注解,包括了:@SpringBootConfiguration,@EnableAutoConfiguration, ...
- 使用IntelliJ IDEA开发前的基本设置,有助于提高开发效率
2.界面字体大小设置 File菜单->Settings->Appearance->Override default fonts by(not recommended): Name:宋 ...
- 【J2EE】在项目中理解J2EE规范
J2EE平台由一整套服务(Service),应用程序接口(API)和协议构成,它对开发企业级应用提供了功能支持.13个核心技术各自是JDBC, JNDI, EJB, RMI, JSP ...
- 自己定义控件-DownSlidingDrawer
一.描写叙述 能够下拉的 SlidingDrawer 二.效果图 图片是网上找到,可是效果是一样的 三.源代码 https://github.com/mentor811/Demo_MySlidingD ...
- tomcat 分别在window 和 Linux上配置SSL-安全问题
公司项目收尾后.通过压力測试后的安全測试.安全測试后中,对于网络传输中数据加密问题存在安全隐患. 须要配置SSL. 简介下SSL协议:SSL或者Secure Socket Layer,是一种同意web ...
- vim 实际行跟屏幕行移动命令
我们使用vim的时候,经常会碰到那种情况,就是我们输入的内容过长,中间一直不换行.当我们一行的长度超出电脑屏幕的时候,我们会发现这时候文字自动换行了.不过,如果你使用行号看的话,其实这新的一行是没有行 ...