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

----------------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ;  i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
const int maxn = 1000 + 5;
 
int n;
 
struct data {
int t , s;
void Read() {
scanf( "%d%d" , &t , &s );
}
bool operator < ( const data &rhs ) const {
return s < rhs.s;
}
};
 
data A[ maxn ];
 
bool jud( int cur ) {
rep( i , n ) {
data &x = A[ i ];
if( ( cur += x.t ) > x.s ) return false;
}
return true;
}
 
int main() {
// freopen( "test.in" , "r" , stdin );
cin >> n;
int L = 0 , R = 0x7fffffff;
rep( i , n ) {
   A[ i ].Read();
   
   R = min( A[ i ].s , R );
   
}
sort( A , A + n );
int ans = -1;
while( L <= R ) {
int mid = ( L + R ) >> 1;
if( jud( mid ) ) 
   ans = mid , L = mid + 1;
   
else 
 
   R = mid - 1;
}
cout << ans << "\n";
return 0;
}

----------------------------------------------------------------------------------------

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

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 539  Solved: 325
[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

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

BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理( 二分答案 )的更多相关文章

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

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

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

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

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

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

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

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

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

    1620: [Usaco2008 Nov]Time Management 时间管理 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 506  Solved: ...

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

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

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

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

  8. BZOJ 1229: [USACO2008 Nov]toy 玩具

    BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...

  9. Bzoj 1229: [USACO2008 Nov]toy 玩具 题解 三分+贪心

    1229: [USACO2008 Nov]toy 玩具 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 338  Solved: 136[Submit] ...

随机推荐

  1. win7 gsoap与vs2010 c++创建Web Service

    ---恢复内容开始--- 之前曾经编写过简单的样例,很久没有碰过,发现已经全部忘记,如今又需要重新巩固一下. 首先是下载gsoap,无法访问官方下载页面,只能在网上搜索,找到一个2.8版本存入云盘以防 ...

  2. BASE64URL解析

    BASE64URL是一种在BASE64的基础上编码形成新的加密方式,为了编码能在网络中安全顺畅传输,需要对BASE64进行的编码,特别是互联网中. BASE64URL编码的流程: .明文使用BASE6 ...

  3. POJ 1721 CARDS(置换群)

    [题目链接] http://poj.org/problem?id=1721 [题目大意] 给出a[i]=a[a[i]]变换s次后的序列,求原序列 [题解] 置换存在循环节,因此我们先求出循环节长度,置 ...

  4. JAVA异常设计原则

    异常是面向对象语言非常重要的一个特性,良好的异常设计对程序的可扩展性.可维护性.健壮性都起到至关重要. JAVA根据用处的不同,定义了两类异常     * Checked Exception: Exc ...

  5. HDU 11488 Hyper Prefix Sets (字符串-Trie树)

    H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...

  6. 如何用LinkedHashMap实现LRU缓存算法

    阿里巴巴笔试考到了LRU,一激动忘了怎么回事了..准备不充分啊.. 缓存这个东西就是为了提高运行速度的,由于缓存是在寸土寸金的内存里面,不是在硬盘里面,所以容量是很有限的.LRU这个算法就是把最近一次 ...

  7. HTML5 postMessage 和 onmessage API 具体应用

    HTML5 postMessage 和 onmessage API 具体应用 随着 HTML5 的发展.了解并熟悉 HTML5 的 API 接口是很重要的.postMessage(send) 和 on ...

  8. javascript操作JSON字符

    1.先要区分JSON字符串和JSON对象 JSON字符串: Var strJSON = “{“Area”:[{“AreaId”:”123”},{“AreaId”:”345”}]}”,   或者 Var ...

  9. 关于tableView刷新

    UITabelView的局部刷新 1. 刷新整个tableView用[self.tableView reloadData]; 2. [self.tableView reloadRowsAtIndexP ...

  10. 转 c#代码访问https服务器以及https的webservice

    最近公司做到WebService项目,但是要通过Https调用,自己在网上搜了半天,终于实现了服务端的Https,但是一直没有找到客户端如何实现,今天终于看到这篇文章,随手记录下来. 具体代码如下: ...