BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理
Description
Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. He has N jobs conveniently numbered 1..N (1 <= N <= 1,000) to accomplish (like milking the cows, cleaning the barn, mending the fences, and so on). To manage his time effectively, he has created a list of the jobs that must be finished. Job i requires a certain amount of time T_i (1 <= T_i <= 1,000) to complete and furthermore must be finished by time S_i (1 <= S_i <= 1,000,000). Farmer John starts his day at time t=0 and can only work on one job at a time until it is finished. Even a maturing businessman likes to sleep late; help Farmer John determine the latest he can start working and still finish all the jobs on time.
N个工作,每个工作其所需时间,及完成的Deadline,问要完成所有工作,最迟要什么时候开始.
Input
* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 contains two space-separated integers: T_i and S_i
Output
* Line 1: The latest time Farmer John can start working or -1 if Farmer John cannot finish all the jobs on time.
题解:
开始时间有单调性,如果从时间t开始能完成,那么从时间t’<t都能完成。
所以我们可以二分一个t。
在t确定后根据贪心每次做Deadline最靠前的任务,模拟一下。
注意无解输出-1。囧
end.
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
//by zrt
//problem:
using namespace std;
int n;
struct N{
int t,s;
friend bool operator < (N a,N b){
return a.s<b.s;
}
}a[1005];
int minn=1<<30;
bool judge(int start){
int t=start;
for(int i=1;i<=n;i++){
if(t+a[i].t>a[i].s) return 0;
else t+=a[i].t;
}
return 1;
}
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i].t,&a[i].s);
minn=min(minn,a[i].s);
}
sort(a+1,a+n+1);
int l=0,r=minn;
if(!judge(0)){
puts("-1");
goto ed;
}
while(r-l>1){
int m=(l+r)>>1;
if(judge(m)){
l=m;
}else r=m;
}
printf("%d\n",l);
ed:;return 0;
}
BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理的更多相关文章
- BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理( 二分答案 )
二分一下答案就好了... --------------------------------------------------------------------------------------- ...
- BZOJ 1620 [Usaco2008 Nov]Time Management 时间管理:贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1620 题意: 有n个工作,每一个工作完成需要花费的时间为tim[i],完成这项工作的截止日 ...
- BZOJ——1620: [Usaco2008 Nov]Time Management 时间管理
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 920 Solved: 569[Submit][Status][Discuss] Description ...
- bzoj 1620: [Usaco2008 Nov]Time Management 时间管理【贪心】
按s从大到小排序,逆推时间模拟工作 #include<iostream> #include<cstdio> #include<algorithm> using na ...
- 1620: [Usaco2008 Nov]Time Management 时间管理
1620: [Usaco2008 Nov]Time Management 时间管理 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 506 Solved: ...
- 【BZOJ】1620: [Usaco2008 Nov]Time Management 时间管理(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1620 一开始想不通啊.. 其实很简单... 每个时间都有个完成时间,那么我们就从最大的 完成时间的开 ...
- bzoj1620 [Usaco2008 Nov]Time Management 时间管理
Description Ever the maturing businessman, Farmer John realizes that he must manage his time effecti ...
- BZOJ 1229: [USACO2008 Nov]toy 玩具
BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...
- Bzoj 1229: [USACO2008 Nov]toy 玩具 题解 三分+贪心
1229: [USACO2008 Nov]toy 玩具 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 338 Solved: 136[Submit] ...
随机推荐
- mysql 中间件 分析
360的Atlas 1.读写分离 2.从库负载均衡 3.IP过滤 4.自动分表 5.DBA可平滑上下线DB 6.自动摘除宕机的DB altas 在10000/s的请求量级应该是毫无问题的 https: ...
- ubuntu系统安装redis
Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串string,链表list,集 合set和有序集合zset.支持在服务器 ...
- Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
出现这个问题,说明oracle的驱动包没有成功加载. 1.检查maven pom.xml有没有引入驱动: <dependency> <group ...
- [转]SharePoint 2010 Download as Zip File Custom Ribbon Action
在SharePoint 2010文档库中,结合单选框,在Ribbon中提供了批量处理文档的功能,比如,批量删除.批量签出.批量签入等,但是,很遗憾,没有提供批量下载,默认的只能一个个下载,当选择多个文 ...
- ThinkPHP函数详解:cache方法
cache方法是3.0版本开始新增的缓存管理方法.注意:3.1.2版本后因cache方法并入原S方法,所以cache方法不再建议使用,用S方法即可. cache 用于缓存设置.获取.删除操作 用法ca ...
- 幻灯片の纯CSS,NO JavaScript
之前就遇到有人问,不用js,纯css实现幻灯片. 那么对于使用纯的css + html 怎样来实现幻灯片呢?下面有几种方法可供参考,有些还不成熟. 方案一:利用css3的animation 例子传送门 ...
- 【转】数据库SQL优化大总结之 百万级数据库优化方案
原帖地址:http://www.cnblogs.com/yunfeifei/p/3850440.html#undefined 1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 or ...
- python中关于正则表达式二
2.2 反向引用 \1, \2... 表达式在匹配时,表达式引擎会将小括号 "( )" 包含的表达式所匹配到的字符串记录下来.在获取匹配结果的时候,小括号包含的表达式所匹配到的字符 ...
- ECMAScript 6 中的一些新特性
1.箭头函数,直接写出来v =>看不出来什么,但是跟传统写法一比较,很直观地就能看出v =>是代替了匿名函数 function(v)的写法,{}与逻辑照旧,但是要注意,=与>之间不能 ...
- I/O端口与I/O内存
端口的概念:设备通过系统总线上的接口与CPU相连,接口电路中含有多种寄存器,CPU向设备读写数据实际上是向接口上的寄存器读写数据,这些寄存器称为I/O端口.一个接口通常包含控制端口,数据端口,状态端口 ...