传送门:http://codeforces.com/contest/898/problem/D

n个闹钟,第i(1in)个闹钟将在第ai(1ai106)分钟鸣响,鸣响时间为一分钟。当在连续的m分钟内,有至少k个闹钟鸣响,则会被叫醒。现要求关闭一些闹钟,使得在任意连续的m分钟内,鸣响的闹钟数量恒小于k

可以贪心地求解这个问题。

首先,设置一个bool数组ison[],当有闹钟在第i分钟鸣响时,记ison[i]=1,否则ison[i]=0。

接下来,扫描整个时间区间[0..MAX_A]。记当前时间为i,记在区间(i-m..i]={i-m+1,...,i-1,i}上开启的闹钟个数为cnt。扫描时维护cnt,当cnt≥k时,将当前的闹钟关闭即可。

参考程序如下:

#include <stdio.h>
#include <stdbool.h>
#define MAX_A 1000001 bool ison[MAX_A]; int main(void)
{
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i < n; i++) {
int a;
scanf("%d", &a);
ison[a] = true;
}
int ans = , cnt = ;
for (int i = ; i < MAX_A; i++) {
if (ison[i]) cnt++;
if (i - m > && ison[i - m]) cnt--;
if (cnt >= k) {
ison[i] = false;
cnt--;
ans++;
}
}
printf("%d\n", ans);
return ;
}

Codeforces 898D - Alarm Clock的更多相关文章

  1. Codeforces Round #451 (Div. 2)-898A. Rounding 898B.Proper Nutrition 898C.Phone Numbers(大佬容器套容器) 898D.Alarm Clock(超时了,待补坑)(贪心的思想)

    A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  2. Codeforces Round #451 (Div. 2) [ D. Alarm Clock ] [ E. Squares and not squares ] [ F. Restoring the Expression ]

    PROBLEM D. Alarm Clock 题 OvO http://codeforces.com/contest/898/problem/D codeforces 898d 解 从前往后枚举,放进 ...

  3. 例子:Alarm Clock with voice Commands Sample

    通过本例子学习: 如何使用自定义字体文件(.TTF) 如何播放声音 动画的使用 Speech 设置闹铃 应用 设置 数据存储到IsolatedStorage 如何使用自定义字体文件(.TTF) < ...

  4. Centos 6.5 安装 chrome , mplayer , alarm , clock

    http://my.oschina.net/jianweizhang/blog/306946 Chrome wget http://chrome.richardlloyd.org.uk/install ...

  5. 【Codeforces Round #451 (Div. 2) D】Alarm Clock

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法+二分. 类似滑动窗口. 即左端点为l,右端点为r. 维护a[r]-a[l]+1总是小于等于m的就好. (大于m就右移左端点) ...

  6. Gym 100531A Alarm Clock (水题)

    题意:给定一个被高亮的数,问你是不是有个时间恰好高亮是这个数. 析:直接暴力,直接暴力,枚举每一位时间,当然也可以枚举时间,能找到就是有,找不到就算了. 代码如下: #pragma comment(l ...

  7. Codeforces Gym100502H:Clock Pictures(KMP算法)

    http://codeforces.com/gym/100502/attachments 题意:有两个时钟上面有n个指针,给出的数字代表指针的角度.问能否在某一时刻使得两个时钟的指针重合. 思路:容易 ...

  8. 【HDOJ】2395 Alarm Clock

    水题. /* 2395 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...

  9. cf898d Alarm Clock

    区间上有 \(n\) 个点,问你为达到目的:长度为 \(m\) 的区间内点的个数都 $ < k$需要去掉多少个点. 贪心.每个区间我们总是去掉最后的,也就是说除非万不得已我们是不会去掉点的. 队 ...

随机推荐

  1. COCOS学习笔记--Button类及其相关控件属性

    一.Button介绍 Button就是button.Cocos中提供了Button类对button进行相关的操作.我们看一下Button类继承关系图: 能够看到.Button是继承自Widget类,W ...

  2. React Native布局实践:开发京东client首页(三)——轮播图的实现

    上篇文章中,我们一起构建了京东client的TabBar.在本文中.将继续向大家介绍京东client首页轮播图及其下发功能button的开发方法,如今就让我们開始吧! 1.相关控件调研 眼下在Gith ...

  3. Codeforces--630B--Moore's Law(快速幂)

     Moore's Law Time Limit: 500MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit ...

  4. jsp 常用标签的使用

    jsp中定义实体bean<jsp:useBean id="clu" class="cn.domain.CacluBean"></jsp:use ...

  5. (Go)08.time示例

    package main import ( "fmt" "time" ) func test() { ) } func main() { now := time ...

  6. 在linux服务器centos上使用svn同步代码到项目中

    一.需求 1.在多人开发过程中代码的管理以及版本的控制是一个很重要的问题,因为在开发过程中我们可能会同时更改过某个文件或者更改过多个文件, 这会导致我们很容易发生错误.所以我们需要一个方式去管理我们的 ...

  7. Windows<小白>详细笔记

    Windows 7 部署 =========================================== ========================================== ...

  8. C#格式化年月日截取

     //if (bm.Name == "DateYear") //年                 //{                 //    bm.Select();   ...

  9. sublime text 快键键

    sublime text 的快捷键ctrl+l                              选择整行(按住-继续选择下行)ctrl+shift+k                    ...

  10. 前端常见面试题总结part2

    今天总结了几道,感觉非常有意思的题,有感兴趣的可以看下,有疑问请留言~ (答案在最后) 考察自执行函数的this指向 审题要细心 var n = 2, obj = { n:2, fn:(functio ...