BZOJ——1620: [Usaco2008 Nov]Time Management 时间管理
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 920 Solved: 569
[Submit][Status][Discuss]
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.
Sample Input
3 5
8 14
5 20
1 16
INPUT DETAILS:
Farmer John has 4 jobs to do, which take 3, 8, 5, and 1 units of
time, respectively, and must be completed by time 5, 14, 20, and
16, respectively.
Sample Output
OUTPUT DETAILS:
Farmer John must start the first job at time 2. Then he can do
the second, fourth, and third jobs in that order to finish on time.
HINT
Source
二分最小开始时间
#include <algorithm>
#include <cstdio> inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
}
const int N();
struct Work {
int t,s;
bool operator < (const Work&x)const
{
if(s==x.s) return t<x.t;
return s<x.s;
}
}job[N]; int ans=-,L,R,Mid,n;
inline bool check(int x)
{
for(int i=; i<=n; ++i)
{
if(x+job[i].t>job[i].s) return ;
x+=job[i].t;
}
return ;
} int Presist()
{
// freopen("manage.in","r",stdin);
// freopen("manage.out","w",stdout); read(n);
for(int t,i=; i<=n; ++i)
read(job[i].t),read(job[i].s);
std::sort(job+,job+n+);
for(R=job[].s-job[].t+; L<=R; )
{
Mid=L+R>>;
if(check(Mid))
{
ans=Mid;
L=Mid+;
}
else R=Mid-;
}
printf("%d\n",ans);
return ;
} int Aptal=Presist();
int main(int argc,char**argv){;}
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 时间管理
Description Ever the maturing businessman, Farmer John realizes that he must manage his time effecti ...
- 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] ...
随机推荐
- Python学习笔记:字符串
字符串 字符串定义:字符串可以使用一对单引号.双引号或三引号来定义,即便是单个字符也会当做字符串来处理(Python中没有字符类型,单个字符也就是只有一个字符的字符串而已). 原始字符串:字符串中反斜 ...
- 水题:51Nod1095-Anigram单词
1095 Anigram单词 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 Description 一个单词a如果通过交换单词中字母的顺序可以得到另外的单词b,那 ...
- 【MySQL】MySQL基础
一.基本语法 [MySQL目录结构]●bin目录,存储可执行文件●data目录,存储数据文件●docs,文档●include目录,存储包含的头文件●lib目录,存储库文件●share,错误信息和字符集 ...
- luogu1208 尼克的任务
倒着推就是了 #include <iostream> #include <cstdio> #include <vector> using namespace std ...
- 深入理解Java虚拟机(精华总结)
作者:战斗民族就是干 转自:http://www.cnblogs.com/prayers/p/5515245.html 一.运行时数据区域 Java虚拟机管理的内存包括几个运行时数据内存:方法区.虚拟 ...
- CI 分页类的使用
分页本身很简单,无非就是一个 [limit $offset, $length] 的过程. $length 是每页显示的数据量,这个是固定的.要确定的就只有 $offset了. 在CI中的分页类同样要依 ...
- python - 路径处理 和 模块导入
# -*- coding:utf-8 -*- '''@project: jiaxy@author: Jimmy@file: study_模块导入.py@ide: PyCharm Community E ...
- 算法理论——Linear SVM
问题引入 下面的三个超平面都起到分类的效果,哪个最好? 答案显然是第三个.为什么? 直觉上,如果现在我们有个测试点,非常靠近右下角的那个红叉叉,也就是说这个点的特征与那个红叉叉非常接近,这时候,我们希 ...
- 爬虫Scrapy框架-Crawlspider链接提取器与规则解析器
Crawlspider 一:Crawlspider简介 CrawlSpider其实是Spider的一个子类,除了继承到Spider的特性和功能外,还派生除了其自己独有的更加强大的特性和功能.其中最显著 ...
- [python 测试框架学习篇] 分享 uiautomator测试框架
uiautomator测试框架 :https://testerhome.com/topics/4194