CodeForces:847D-Dog Show
D. Dog Show
time limit per test2 seconds
memory limit per test256 megabytes
Problem Description
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win!
On the show a dog needs to eat as many bowls of dog food as possible (bottomless stomach helps here). Dogs compete separately of each other and the rules are as follows:
At the start of the show the dog and the bowls are located on a line. The dog starts at position x = 0 and n bowls are located at positions x = 1, x = 2, …, x = n. The bowls are numbered from 1 to n from left to right. After the show starts the dog immediately begins to run to the right to the first bowl.
The food inside bowls is not ready for eating at the start because it is too hot (dog’s self-preservation instinct prevents eating). More formally, the dog can eat from the i-th bowl after ti seconds from the start of the show or later.
It takes dog 1 second to move from the position x to the position x + 1. The dog is not allowed to move to the left, the dog runs only to the right with the constant speed 1 distance unit per second. When the dog reaches a bowl (say, the bowl i), the following cases are possible:
- the food had cooled down (i.e. it passed at least ti seconds from the show start): the dog immediately eats the food and runs to the right without any stop,
- the food is hot (i.e. it passed less than ti seconds from the show start): the dog has two options: to wait for the i-th bowl, eat the food and continue to run at the moment ti or to skip the i-th bowl and continue to run to the right without any stop.
After T seconds from the start the show ends. If the dog reaches a bowl of food at moment T the dog can not eat it. The show stops before T seconds if the dog had run to the right of the last bowl.
You need to help your dog create a strategy with which the maximum possible number of bowls of food will be eaten in T seconds.
Input
Two integer numbers are given in the first line - n and T (1 ≤ n ≤ 200 000, 1 ≤ T ≤ 2·109) — the number of bowls of food and the time when the dog is stopped.
On the next line numbers t1, t2, …, tn (1 ≤ ti ≤ 109) are given, where ti is the moment of time when the i-th bowl of food is ready for eating.
Output
Output a single integer — the maximum number of bowls of food the dog will be able to eat in T seconds.
Note
In the first example the dog should skip the second bowl to eat from the two bowls (the first and the third).
- 题意就是一只狗,去吃一列的饭,每次移动到下一个碗花费1秒的时间,瞬间吃完,每个饭的冷却时间为第c[i]秒(只有当饭冷却之后狗才能吃)。问在m秒内这只狗最多能吃多少碗饭。
- 这是一个经典的贪心问题,狗每次尽可能的多吃饭。就是处理在等待的时间能不能吃更多的饭。枚举第m秒到达的每一个碗。主要是看实现方法。
/*可以把狗想象成可以后悔,狗要将遇到的每一个碗里的饭都吃下去,
当狗发现后面还可以吃但是时间不够了的时候,狗可以把饭吐出来
而老天把狗等待这个饭的时间还给狗,优先队列模拟狗肚子里的饭
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
priority_queue <int> qu;
int n,m;
scanf("%d%d",&n,&m);
int Max = 0;
for(int i=1;i<=min(m-1,n);i++)
{
int temp;
scanf("%d",&temp);
while(!qu.empty() && qu.top() >= m-i)//每次时间不够的时候去除等待时间最长的那个碗
qu.pop();
if(max(temp,i) < m)
qu.push(temp-i);
Max = max((int)qu.size(),Max);
}
printf("%d",Max);
return 0;
}
CodeForces:847D-Dog Show的更多相关文章
- Arduino - 看门狗定时器(WDT:Watch Dog Timer)
看门狗定时器(WDT:Watch Dog Timer)实际上是一个计数器. 一般给看门狗一个大数,程序开始运行后看门狗开始倒计数. 如果程序运行正常,过一段时间CPU应该发出指令让看门狗复位,令其重新 ...
- CodeForces:#448 div2 B. XK Segments
传送门:http://codeforces.com/contest/895/problem/B B. XK Segments time limit per test1 second memory li ...
- CodeForces:#448 div2 a Pizza Separation
传送门:http://codeforces.com/contest/895/problem/A A. Pizza Separation time limit per test1 second memo ...
- YUM:Yellow dog Updater Modified
1. 什么是YUM YUM(全称为 Yellow dog Updater Modified) 是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器.基于RPM包管理,能够从 ...
- LCD实验学习笔记(三):WATCH DOG
看门狗是为了能够防止程序跑飞用的.程序应该定时的去喂狗.如果程序跑飞了,那么就不会去喂狗了.如果超过了喂狗的时间,那么狗就会生成一个信号来reset CPU.一般程序不需要,特殊情况下需要这种机制. ...
- Codeforces:68A-Irrational problem(暴力大法好)
A- Irrational problem p Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64 De ...
- CodeForces:148D-D.Bag of mice
Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Program Description Th ...
- CodeForces:699B-One Bomb
B. One Bomb time limit per test1 second memory limit per test256 megabytes Problem Description You a ...
- SIFT算法:DoG尺度空间生产
SIFT算法:DoG尺度空间生产 SIFT算法:KeyPoint找寻.定位与优化 SIFT算法:确定特征点方向 SIFT算法:特征描述子 目录: 1.高斯尺度空间(GSS - Gauss Scal ...
随机推荐
- MD5加密的方法
#region MD5加密 /// <summary> /// MD5加密 /// </summary> /// <param name="strPwd&quo ...
- jvm内存溢出的三种情况以及解决办法
1 前言相信有一定java开发经验的人或多或少都会遇到OutOfMemoryError的问题,这个问题曾困扰了我很长时间,随着解决各类问题经验的积累以及对问题根源的探索,终于有了一个比较深 ...
- 解决java.lang.NoClassDefFoundError: javax/xml/rpc/service错误的方法
最近在做WebService项目,本地测试没有问题,打算部署到服务器上,但是部署后,访问时出现了如下图1的错误: 图1 图1报的是没有找到定义的类的错误.刷新页面有又出现了另外“新”的错误: 图2 根 ...
- 2017 清北学堂 Day 6终极考试报告
预计分数: 100+70+70 = 240 实际假分数 : 40+80+70= 190 in cena(好吧不得不承认这个分数,,,,,,=.=) 实际真分数 : 100+80+100 = 280 ...
- POSTGRESQL 存储过程实战
转了N多的SQL语句,可是自己用时,却到处是坑啊,啊,啊!!!!!!!!!!!!!!! 想写一个获取表中最新ID值. 上代码 CREATE TABLE department( ID INT PRIMA ...
- windows下Mongodb和Memcached安装笔记
MongoDB安装: D:\ProgramFiles\MongoDBServer3.2\bin\mongod --dbpath D:\mongoData D:\ProgramFiles\MongoDB ...
- Azure School女神相邀,把每分钟都过的更充实
也许你不姓「牛」,但是你技术牛啊 所以,请容我叫你一声「牛郎」 (讲真,只是因为你技术牛,不是其他啥原因哈) 平时忙到昏天黑地,一心一意为技术的你 注意看一下日历,因为: !!!七夕节(8月28日)到 ...
- MySQL备份还原介绍
window系统下 1.导出整个数据库mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u dbuser -p dbname > dbname.sql ...
- codevs 3278 最小m 段和问题
时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定 n 个整数(不一定是正整数)组成的序列,现在要求将序列分割为 m 段,每段 ...
- 原生JS forEach()和map()遍历,jQuery$.each()和$.map()遍历
一.原生JS forEach()和map()遍历 共同点: 1.都是循环遍历数组中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项item,当前 ...