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 ...
随机推荐
- border、margin、padding三者的区别
当你写前端的时候,肯定会遇到border,margin和padding这几个单词. 如: padding: 16px 0; margin: 0 10px; 在CSS中,他们是表示距离的东西,很多人刚开 ...
- RovingUI组件库-包含堆栈式通知提醒框(Toast)的小程序组件库
RovingUI是个人在开发小程序过程中将用到的组件集合而成的一个UI库,包含一些基本通用组件(按钮.栅格.通用样式.徽标.通知和面包屑). 源起得归于我在开发中没有找到现成的堆栈式提醒框(比如ant ...
- C#高级编程 (第六版) 学习 第二章:C#基础
第二章 基础 1,helloworld示例: helloworld.cs using System; using System.Collections.Generic; using System.Li ...
- Java 异常总结
Throwablede类是 Java 语言中所有错误或异常的超类. 两个子类的实例,Error 和 Exception Error 是 Throwablede 的子类,用于指示合理的应用程序不应该试图 ...
- 获取Class实例的三种方式
方式一: 通过类.枚举.接口.注解.数组类型.原生类型的名称.class package com.rong.test; public class TestClass { public static ...
- 【Linux】- 六个超赞的字符画生成器
ASCII是一个非常吸引人的字符编码系统,在计算机,通讯设备,以及其他设备中,通过它来用代码表示字符.新生代的人可能会觉得它已经过时了,但是那些熟悉它的人会懂得ASCII是多么的独特.我们在这里为你准 ...
- centos系统下禁用笔记本触控板
最近把零几年的老爷笔记本拿出来用,使用windows系统实在太卡了,于是折腾安装上Centos系统了,但是在使用的过程中发现鼠标经常失效.使用了多种方法(比如:http://blog.csdn.net ...
- Spring 学习 3- AOP
什么是AOP aop就是纵向的编程,业务1和业务2都需要一个共同的操作,与其往每个业务中都添加同样的代码,不如写一遍代码,让两个业务共同使用这段代码. spring中面向切面编程用的是代理模式,它的实 ...
- 【Asp.Net Core】在Visual Studio 2017中使用Asp.Net Core构建Angular4应用程序
前言 Visual Studio 2017已经发布了很久了.做为集成了Asp.Net Core 1.1的地表最强IDE工具,越来越受.NET系的开发人员追捧. 随着Google Angular4的发布 ...
- elsarticle模板 去掉摘要前后的两条横线
参考:http://www.newsmth.net/nForum/#!article/TeX/316697?au=ericfire 如图:使用elsarticle模板修改PDF格式,去掉摘要前后的横线 ...