BZOJ 1620 [Usaco2008 Nov]Time Management 时间管理:贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1620
题意:
有n个工作,每一个工作完成需要花费的时间为tim[i],完成这项工作的截止日期为dead[i]。
问你在保证所有工作按时完成的前提下,最晚什么时候开始工作。
(每天从时刻0开始算。如果无论如何都完成不了,输出-1)
题解:
贪心。
先将所有工作按dead从大到小排序。
当前开始工作的时间为start(初始为INF)。
对于每个工作,start一定要满足两个条件:
start <= dead - tim (最后一刻才完成这项工作的开始时间)
start + tim <= 原来的start (这项工作做完了之后,才能开始别的工作)
所以start = min(start - tim, dead - tim)
AC Code:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define MAX_N 1005
#define INF 10000000 using namespace std; struct Work
{
int tim;
int dead;
Work(int _tim,int _dead)
{
tim=_tim;
dead=_dead;
}
Work(){}
friend bool operator < (const Work &a,const Work &b)
{
return a.dead>b.dead;
}
void read_work()
{
cin>>tim>>dead;
}
}; int n;
int start=INF;
Work work[MAX_N]; void read()
{
cin>>n;
for(int i=;i<n;i++)
{
work[i].read_work();
}
} void solve()
{
sort(work,work+n);
for(int i=;i<n;i++)
{
Work now=work[i];
start=min(start-now.tim,now.dead-now.tim);
}
} void print()
{
if(start>=) cout<<start<<endl;
else cout<<-<<endl;
} int main()
{
read();
solve();
print();
}
BZOJ 1620 [Usaco2008 Nov]Time Management 时间管理:贪心的更多相关文章
- BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理( 二分答案 )
二分一下答案就好了... --------------------------------------------------------------------------------------- ...
- 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 时间管理
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 玩具 题解 三分+贪心
1229: [USACO2008 Nov]toy 玩具 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 338 Solved: 136[Submit] ...
- BZOJ 1229 [USACO2008 Nov]toy 玩具(三分+贪心)
[题木链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1229 [题目大意] 每天对玩具都有一定的需求ni,每天可以花f价值每条购买玩具, 当天 ...
随机推荐
- JNA 相关问题
JNA 相关问题 结构体对齐问题 要注意调用的c库字段对齐方式的相关设置. #pragma pack (push,1) #pragma pack(pop) jna中提供了4种对齐方式: /** Use ...
- xshell配置
字体:DejaVu Sans Mono 或者 Consolas 11号
- Unity -- 入门教程三
进入这个页面,按编译器版本进行下载,我用的是2010,所以要下载这个. 安装就不用我教了,下面开始看我是如何导入Unity VS的. 点击Import之后我们会发现并没有发生什么,但是接下来我们按一下 ...
- 微服务指南走北(三):Restful API 设计简述
API的定义取决于选择的IPC通信方式,假设是消息机制(如 AMQP 或者 STOMP).API则由消息频道(channel)和消息类型.假设是使用HTTP机制,则是基于请求/响应(调用http的ur ...
- hadoop常见错误
hadoop常见错误集锦: 1.DataXceiver error processing WRITE_BLOCK operation ERROR org.apache.hadoop.hdfs.serv ...
- C 标准库 - <float.h>
C 标准库 - <float.h> 简介 C 标准库的 float.h 头文件包含了一组与浮点值相关的依赖于平台的常量.这些常量是由 ANSI C 提出的,这让程序更具有可移植性.在讲解这 ...
- 网络通讯框架MINA和XSCOCKET的简单比较
http://www.blogjava.net/ghostdog/archive/2008/06/10/MinaVsXsocket.html实在无聊,考虑把当前应用的通讯模式由http移植为socke ...
- gulp-gulpfile.js语法说明
关于gulpfile文件: 直接上代码吧!! /*! * gulp * $ npm install gulp gulp-ruby-sass gulp-cached gulp-uglify gulp-r ...
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...
- WWDC2014苹果的“软件”发布会
WWDC 2014 苹果的"软件"发布会 在今年的 6 月 2 日到 6 日,苹果照例举行了一年一次的全球开发者大会(World Wide Developer Conference ...