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 ...
随机推荐
- win10自带中文输入法的用户体验
用户界面: 貌似没有什么界面,不过我感觉这就是最大的优点,没有过度渲染的界面,没有烦人的推送.弹窗,没有定期不定期的更新提示,简洁也是我使用这款输入法的最主要的原因 记住用户的选择: 这点我认为win ...
- CS小分队第一阶段冲刺站立会议(5月13日)
昨日成果:昨日由于课程满课,未进行项目的制作 遇到困难:/ 今天计划:为2048和扫雷添加游戏音效,和组员一起合作对扫雷进行外观美化,学习程序生成时渐隐等特效
- CSS3:不可思议的border属性
在CSS中,其border属性有很多的规则.对于一些事物,例如三角形或者其它的图像,我们仍然使用图片代替.但是现在就不需要了,我们可以用CSS形成一些基本图形,我分享了一些关于这方面的技巧. 1.正三 ...
- 【树上DFS】Tree and Polynomials
http://codeforces.com/gym/101372 D push1[i][k]:所有操作1总共要让节点i下推多少系数k push2[i][k]:所有操作2总共要让节点i上推多少系数k s ...
- 软工网络15个人作业4--alpha阶段个人总结
一.个人总结 自我评价表 类别 具体技能和面试问题 现在的回答 毕业找工作 语言 最拿手的语言之一,代码量是多少 java,代码量大概两三千行吧 语言 最拿手的语言之二,代码量是多少 python,代 ...
- 使用kdump内核调试工具遇到的问题及解决
修改linux内核代码或者内核模块的时候,搞不好就会造成linux死机崩溃,crash死机后/var/log/kern.log里面不会有任何异常信息记录.这时候kdump就会派上用场了,网上kdump ...
- erlang随机排列数组
参考karl's answer 1> L = lists:seq(1,10). [1,2,3,4,5,6,7,8,9,10] Associate a random number R with e ...
- 2nd 词频统计效能测试
词频统计效能测试 使用性能分析工具分析结果如下 :
- 安装php先行库
libmcrypt libconv mhash ./configure --prefix=/usr/local mcrypt 安装完成后在当前目录还要 /sbin/ldconfig ./config ...
- hdu-题目:1058 Humble Numbes
http://acm.hdu.edu.cn/showproblem.php?pid=1058 Problem Description A number whose only prime factors ...