CF767 B. The Queue 贪心+细节
题意:一个业务开始时间为s,结束时间为f,一个人办护照的时间需要m分(如果在x时开始服务,且x+m==f那么还是合法的),你可以选择任意时间到达,但如果你和其他人同时到达,你要排在他的后面。问什么时候去等待时间最小。
思路:贪心,对所有人枚举在他之前1分钟到达和同时到达的情况。 因为对于任意一个人,在他1分前到达时,能够保证必定先于该人服务,且等待前一个人服务时间最小,而同时到达时能保证必定比后面的人先服务。 不断更新开始的时间为前一个人结束服务时间,并更新最小等待时间。 要注意特殊情况,如果有人0时到达,那么不可能比他先到了。
/** @Date : 2017-04-17 20:26:35
* @FileName: 767B greed.cpp
* @Platform: Windows
* @Author : Lweleth (SoundEarlf@gmail.com)
* @Link : https://github.com/Lweleth
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; LL a[N];
int main()
{
LL s, f, m;
int n ;
while(cin >> s >> f >> m)
{
cin >> n;
for(int i = 0; i < n; i++)
scanf("%lld", a + i); LL ls = 1e15+10;
LL mi = 1e15+10;
for(int i = 0; i < n; i++)
{
int ma = max(a[i] - 1, s);
if(a[i] == 0 || a[i] + m > f)
continue;
if(ma + m <= f && s - (a[i] - 1) <= ls)
{
ls = s - (a[i] - 1);
mi = min(a[i] - 1, s);
}
s = max(s, a[i]) + m;
}
if(s + m <= f)
mi = s;
printf("%lld\n", mi);
}
return 0;
}
CF767 B. The Queue 贪心+细节的更多相关文章
- Codeforces Round #303 (Div. 2) D. Queue —— 贪心
题目链接:http://codeforces.com/problemset/problem/545/D 题解: 问经过调整,最多能使多少个人满意. 首先是排序,然后策略是:如果这个人对等待时间满意,则 ...
- BZOJ 4278: [ONTAK2015]Tasowanie 后缀数组 + 贪心 + 细节
Code: #include <bits/stdc++.h> #define setIO(s) freopen(s".in", "r", stdin ...
- 【bzoj2424】[HAOI2010]订货 费用流
原文地址:http://www.cnblogs.com/GXZlegend/p/6825296.html 题目描述 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di, ...
- Codeforces Round #392 (Div. 2)-758D. Ability To Convert(贪心,细节题)
D. Ability To Convert time limit per test 1 second Cmemory limit per test 256 megabytes input standa ...
- 【bzoj1727】[Usaco2006 Open]The Milk Queue 挤奶队列 贪心
题目描述 Every morning, Farmer John's N (1 <= N <= 25,000) cows all line up for milking. In an eff ...
- Codeforces Round #398 (Div. 2) A B C D 模拟 细节 dfs 贪心
A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #515 (Div. 3) B. Heaters【 贪心 区间合并细节 】
任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limi ...
- Codeforces Round #303 (Div. 2) D. Queue 水题贪心
题目: 题意:给你n个数值,要求排列这个序列使得第k个数值的前K-1个数的和>=第k个数值的个数尽可能多: #include <iostream> #include <cstd ...
- hdu1052Tian Ji -- The Horse Racing(贪心,细节多)
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
随机推荐
- 《JavaScript》JS中的常用方法attr(),splice()
1.jquery中用attr()方法来获取和设置元素属性,attr是attribute(属性)的缩写,在jQuery DOM操作中会经常用到attr(),attr()有4个表达式. attr(属性名) ...
- php addslashes和stripslashes函数
addslashes — 使用反斜线引用字符串 stripslashes — 反引用一个引用字符串 Example #1 一个 addslashes() 例子 <?php$str = &qu ...
- IT就业·软件工程之我见
随着计算机技术的飞速发展,让人们深切感受到科技让生活更美好的真正含义. 现如今我们的正常生活,社交都越来越离不开网络和终端,因特网和各种终端设备的组合让我们即使相距千里,也能面对面对话交流:购物,我们 ...
- 安恒杯-babysql
1. 库名 ?id= and extractvalue(,(select group_concat(0x3a,schema_name) from information_schema.schemata ...
- EL语法 ${person.id} 这里面的id指的是实例对象的成员变量
EL语法 ${person.id} 这里面的id指的是实例对象的成员变量
- CSS预处理语言-less 的使用
Less 是一门 CSS 预处理语言,它扩展了 CSS 语言,增加了变量.Mixin.函数等特性,使 CSS 更易维护和扩展. Less 可以运行在 Node 或浏览器端. Less的编译处理 作为一 ...
- python中括号的使用
1. 列表list是用[ ]包住的以逗号分隔的数据集合 所有对列表的解析均采用[ ],不论是元素引用或取值 [ ]表示空列表 2. 字典由键-值(key-value)对构成,一般可采用{ }表示 取字 ...
- oracle 插入单引号
INSERT INTO tb (id) values ('hellp'||''''||'张三') --等于 hellp'张三
- Unity3D实现3D立体游戏原理及过程
Unity3D实现3D立体游戏原理及过程 183 0 0 下面的教程是我今天整理的资料,教大家一步步完成自己的3D立体游戏,并向大家介绍一些3D成像的原理. 理论上,每个普通的非立体3 ...
- linux-----遇到的问题----tab键不补全sh文件不能运行
在linux上部署tomcat,进入bin目录后 遇到了tab键不补全sh文件不能运行的情况. 如果自己输入sh文件名后也会报错: [x@web bin]$ ./startup.shbash: ./s ...