Codeforces Round #451 (Div. 2) D. Alarm Clock
来源:互联网 发布:行知小学 编辑:程序博客网 时间:2024/06/05 20:52
题目大意
删去最少的点使没有连续的长度m的一段有超过k个点。
题解
从前到后找,有一个时刻不符合条件就把当前点删掉,显然这样是最优的。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;int read(){ char ch=getchar();int f=0,x=1; while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();} while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();} return f*x;}int n,a[500005],s[500005],top=0,tail=1,ans,m,k;int main(){ n=read();m=read();k=read()-1; for(int i=1;i<=n;i++) a[i]=read(); sort(a+1,a+n+1); for(int i=1;i<=n;i++) { while(top>=tail&&s[tail]<=a[i]-m) { tail++; } s[++top]=a[i]; while(top-tail+1>k) { top--; ans++; } } cout<<ans;}
阅读全文
0 0
- Codeforces Round #451 (Div. 2) D. Alarm Clock
- Codeforces Round #451 (Div. 2) D. Alarm Clock (贪心+双指针)
- Codeforces Round #229 (Div. 2) Inna and Alarm Clock
- Codeforces Round #229 (Div. 2)A. Inna and Alarm Clock
- Codeforces Round #229 (Div. 2) A. Inna and Alarm Clock
- Codeforces Round #229 (Div. 2) A. Inna and Alarm Clock
- codeforces 898 D. Alarm Clock【贪心 + 模拟】
- Codeforces Round #451 (Div. 2) D
- Codeforces Round #451 (Div. 2) D
- Codeforces 898D Alarm Clock (贪心好题)
- Codeforces Round #103 (Div. 2) D
- Codeforces Round #104 (Div. 2) D
- Codeforces Round #105 (Div. 2) D
- Codeforces Round #139 (Div. 2) D. Snake
- Codeforces Round #155 (Div. 2) D-rats
- Codeforces Round #159 (Div. 2) D sum
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round#186(Div 2) D
- Java https访问
- [Err] ORA-02289: sequence does not exist序列不存在
- Android 7.1 GUI系统-窗口管理WMS-窗口大小计算(五)
- Linux 安装vsftpd
- django CKeditor 正常显示富文本
- Codeforces Round #451 (Div. 2) D. Alarm Clock
- Windows下使用Python配制环境以及打开方式
- 迷宫系列(三)利用BFS/DFS的数据得到最短路/通路
- 推荐系统经典论文文献及业界应用
- 门面模式
- Mahout学习之Mahout简介、安装、配置、入门程序测试
- 职业生涯的思考:产品经理的终极目标-通过产品让生活变得更美好
- TOJ 1048: 简易版最长序列
- 一句话理解复杂语法