1620: [Usaco2008 Nov]Time Management 时间管理

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 506  Solved: 306
[Submit][Status]

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

4
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

2

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

Silver

题解:坑爹啊,这次居然CE,吓我一跳——打开一看,代码没复制全TuT。。。突然觉得其实bzoj上面贪心的题才是最令人不敢下手的,看了半天才尝试性的写了个贪心程序,然后碰运气,有时候AC,有时候直接跪。。。书归正传,这个题其实就是先按照deadline时间排个序,然后不断的往前减当前任务消耗的时间,假如出现了减去后小于0的情况,就出-1,还有注意每次减去后到了下一次,然后要和这个新的任务deadline比较小,假如deadline更小的话,则取deadline再减,否则凉拌。。。

 type
arr=array[..] of longint;
var
i,j,k,l,m,n:longint;
a,b:arr;
procedure swap(var x,y:longint);
var z:longint;
begin
z:=x;x:=y;y:=z;
end;
function min(x,y:longint):longint;
begin
if x<y then min:=x else min:=y;
end;
procedure sort(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;j:=r;
x:=a[(l+r) div ];
repeat
while a[i]<x do inc(i);
while a[j]>x do dec(j);
if I<=j then
begin
swap(a[i],a[j]);
swap(b[i],b[j]);
inc(i);dec(j);
end;
until I>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
readln(n);
for i:= to n do
readln(b[i],a[i]);
sort(,n);
l:=a[n];
for i:=n downto do
begin
l:=min(l,a[i]);
l:=l-b[i];
if l< then
begin
writeln(-);
halt;
end;
end;
writeln(l);
end.

1620: [Usaco2008 Nov]Time Management 时间管理的更多相关文章

  1. BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理( 二分答案 )

    二分一下答案就好了... --------------------------------------------------------------------------------------- ...

  2. 【BZOJ】1620: [Usaco2008 Nov]Time Management 时间管理(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1620 一开始想不通啊.. 其实很简单... 每个时间都有个完成时间,那么我们就从最大的 完成时间的开 ...

  3. BZOJ 1620 [Usaco2008 Nov]Time Management 时间管理:贪心

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1620 题意: 有n个工作,每一个工作完成需要花费的时间为tim[i],完成这项工作的截止日 ...

  4. BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理

    Description Ever the maturing businessman, Farmer John realizes that he must manage his time effecti ...

  5. BZOJ——1620: [Usaco2008 Nov]Time Management 时间管理

    Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 920  Solved: 569[Submit][Status][Discuss] Description ...

  6. bzoj 1620: [Usaco2008 Nov]Time Management 时间管理【贪心】

    按s从大到小排序,逆推时间模拟工作 #include<iostream> #include<cstdio> #include<algorithm> using na ...

  7. bzoj1620 [Usaco2008 Nov]Time Management 时间管理

    Description Ever the maturing businessman, Farmer John realizes that he must manage his time effecti ...

  8. bzoj1620 / P2920 [USACO08NOV]时间管理Time Management

    P2920 [USACO08NOV]时间管理Time Management 显然的贪心. 按deadline从大到小排序,然后依次填充时间. 最后时间为负的话那么就是无解 #include<io ...

  9. P2920 [USACO08NOV]时间管理Time Management

    P2920 [USACO08NOV]时间管理Time Management 题目描述 Ever the maturing businessman, Farmer John realizes that ...

随机推荐

  1. 第一部分 DotNET与C#概述

    DOTNET是.NET Framework框架分为公共语言运行时(CLR)和框架类库(FCL). C#是C#(CSharp)语言(编程语言). 模式: 硬件--->操作系统OS分为非托管应用程序 ...

  2. Quercus

    其实,我不确定Quercus是否可以被认定为一门JVM语言:其次Quercus这个东东分开源版与商业版,开源版只能解释执行.而商业版能编译成Java字节码. 但我知道国内,阿里巴巴很早就在使用它,当然 ...

  3. SuperSocket入门(二)- 探索AppServer、AppSession,Conmmand和App.config

          在上一篇文章中,我们已经了解到了如何在SuperSocket处理客户端请求. 同时我们可能会发现一个问题,如果我们的服务器端包含有很多复杂的业务逻辑,这样的switch/case代码将会很 ...

  4. 《JAVASCRIPT高级程序设计》选择框脚本和富文本编辑

    一.选择框脚本 选择框也是表单的一个字段,是通过<select>和<option>元素来创建的,需要使用javascript来控制.选择框拥有以下的属性和方法: 以下介绍一些选 ...

  5. 第七届蓝桥杯javaB组真题解析-生日蜡烛(第二题)

    题目 /* 生日蜡烛 某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛. 现在算起来,他一共吹熄了236根蜡烛. 请问,他从多少岁开始过生日party的? 请填写他开始 ...

  6. vs2015 动态链接库问题

    问题: 最近要用vs2015编写一个动态链接库,生成动态链接库后,换到另一台windows下发现无法使用. 使用depends检查发现原因是缺少 MSVCP140.DLL等动态链接库. 解决: 将编译 ...

  7. python3 - 通过BeautifulSoup 4抓取百度百科人物相关链接

    导入需要的模块 需要安装BeautifulSoup from urllib.request import urlopen, HTTPError, URLError from bs4 import Be ...

  8. C语言 extern学习1

    没有头文件时,通过本文件内的函数声明来确定定义域,实现功能: //单文件测试 #include <stdio.h> /* 经测试,C语言环境下子函数默认是void型:所以可省略不写 为严谨 ...

  9. java socket初步学习一 ( tcp)

    Java socket通信程序: 第一版本: 实现功能: 服务器地址:127.0.0.1  端口:5050 客户机:端口5050 客户端发送字符:“t” 服务器接收到该字符并回复:“r” 流程: 建立 ...

  10. 事件机制-Spring 源码系列(4)

    事件机制-Spring 源码系列(4) 目录: Ioc容器beanDefinition-Spring 源码(1) Ioc容器依赖注入-Spring 源码(2) Ioc容器BeanPostProcess ...