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

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

#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. 11-3URLTestDemo实例操作完成URL单元测试

    11-3URLTestDemo 1.File -> New -> Project 在左边模板中选择Visual C#里的Web,对应到的项目类型选择ASP.NET MVC3 Web App ...

  2. oracle在一个字符串中查找某个字符出现过几次

    SELECT LENGTH(REGEXP_REPLACE(REPLACE('123,45,6,5', ',', '@'),  '[^@]+',  '')) COUNT FROM DUAL; 返回结果为 ...

  3. dp-史上最戳最长最臭代码-hdu-4733-G(x)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4733 题目大意: 定义G(x)=x⊕(x>>1).给两个由0.1.?组成的长度相同的字符 ...

  4. iOS 检测更新版本

    获取app版本URL 数字是appID,在开发者账号app信息中可以找到 #define APP_URL @"http://itunes.apple.com/cn/lookup?id=116 ...

  5. android播放html5视频,仅仅有声音没有图像视频

    在AndroidManifest.xm中l增加 <activity .... android:hardwareAccelerated="true" />

  6. Random类短时间大量随机重复的问题

    先声明一下,我是在那篇文章上看到的解决方法: http://dl.download.csdn.net/down10/20141103/4b173214e41ff3207305c2470524b0f3. ...

  7. 获取多个div,点击第几个,显示第几个

    1.闭包:函数内部又定义了一个函数,内部函数引用外部函数的变量,就构成了闭包. <script type="text/javascript"> var divs = d ...

  8. 【Java】 实现一个简单文件浏览器(1)

    学习Java的Swing的时候写的一个超简单文件浏览器 效果如图: 项目结构: 这里面主要用了两个控件,JTree和JTable 下面先说下左侧的文件树如何实现: 首先是FileTree类,继承于JT ...

  9. php基础教程笔记2

    如果学过c.java,php的语法不学即会,但是不同的是php是一种脚本语言,需要解释器才能运行.php又和js不同,js是客户端语言,而php运行在服务器端,它无法获取客户端浏览器信息.但是php又 ...

  10. Oracle的大数据类型,BIG DATA TYPE

    1.CLOB 字符LOB类型,主要用于存储大型英文字符 2.NCLOB 国际语言字符LOB类型,主要用于存储大型非英文字符 3.BLOB 二进制LOB类型,主要用于存储二进制数据 4.BFILE 二进 ...