P2920 [USACO08NOV]时间管理Time Management

显然的贪心。

按deadline从大到小排序,然后依次填充时间。

最后时间为负的话那么就是无解

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define re register
using namespace std;
int max(int a,int b){return a>b?a:b;}
struct data{
int t,dl;
bool operator < (const data &tmp) const{return dl>tmp.dl;}
}a[];
int n,tt,ans;
int main(){
scanf("%d",&n);
for(re int i=;i<=n;++i) scanf("%d%d",&a[i].t,&a[i].dl);
sort(a+,a+n+); tt=a[].dl;
for(re int i=;i<=n;++i){
tt=min(tt,a[i].dl); tt-=a[i].t;//注意在deadline前完成所以要取min
}tt< ? printf("-1"):printf("%d",tt);
return ;
}

bzoj1620 / P2920 [USACO08NOV]时间管理Time Management的更多相关文章

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

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

  2. 洛谷 P2920 [USACO08NOV]时间管理Time Management

    传送门 题目大意: 每个工作有截至时间和耗费时间,n个工作求最小开始时间. 题解: 贪心 从n-1安排,让结束时间尽量的晚. 注意:优先级 cout<<st<0?-1:st;  (X ...

  3. [LUOGU] P2920 [USACO08NOV]时间管理Time Management

    见7.3测试 #include<iostream> #include<algorithm> #include<cstdio> using namespace std ...

  4. 题解 P2920 【[USACO08NOV]时间管理Time Management】

    题面 作为一名忙碌的商人,约翰知道必须高效地安排他的时间.他有N工作要 做,比如给奶牛挤奶,清洗牛棚,修理栅栏之类的. 为了高效,列出了所有工作的清单.第i分工作需要T_i单位的时间来完成,而 且必须 ...

  5. [USACO08NOV]时间管理Time Management(排序,贪心)

    题目描述 作为一名忙碌的商人,约翰知道必须高效地安排他的时间.他有N工作要 做,比如给奶牛挤奶,清洗牛棚,修理栅栏之类的. 为了高效,列出了所有工作的清单.第i分工作需要T_i单位的时间来完成,而 且 ...

  6. [USACO08NOV]时间管理Time Management

    题目描述 Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. H ...

  7. CMSIS-RTOS 时间管理之时间延迟Time Delay

    时间管理 Time Management 此RTOS除了可以把你的应用代码作为线程运行,它还可以提供一些时间服务功能,使用这些功能你就可以访问RTOS的一些系统调用. 时间延迟Time Delay 在 ...

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

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

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

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

随机推荐

  1. 64位ubuntu下用code::blocks IDE配置opengl开发环境

    http://jingyan.baidu.com/article/c74d60007d104f0f6b595d6d.html 样例程序: #include <GL/glut.h> #inc ...

  2. 《C++ Primer Plus》第7章 函数——C++的编程模块 学习笔记

    函数是C++的编程模块.要使用函数,必须提供定义和原型,并调用该函数.函数定义是实现函数功能的代码:函数原型描述了函数的接口:传递给函数的值的书目和种类以及函数的返回类型.函数调用使得程序将参数传递给 ...

  3. 一个java源文件中是否可以包括多个类(非内部类)?有何限制?

    可以有多个类,但只能有一个public的类,并且public的类名必须与文件名一致.

  4. C# Timer自带定时器

    官方文档 https://msdn.microsoft.com/zh-cn/library/system.timers.timer.aspx using System; using System.Ti ...

  5. redis基础----->redis的基本使用(一)

    这里我们就在虚拟机中安装redis,并且使用java和python实现简单的操作.深情是我承担不起的重担,情话只是偶尔兑现的谎言. redis的使用 下载地址:https://redis.io/.安装 ...

  6. Java三方---->Thumbnailator框架的使用

    Thumbnailator是一个用来生成图像缩略图的 Java类库,通过很简单的代码即可生成图片缩略图,也可直接对一整个目录的图片生成缩略图.有了它我们就不用在费心思使用Image I/O API,J ...

  7. linux 中怎样返回上一层目录的命令?

    可以使用cd命令,cd命令的功能是切换到指定的目录:命令格式:cd [目录名]目录名有几个符号有特殊的含义,“..”代表上一级目录.“~”代表HOME目录.“-”代表前一目录.因此返回上一级目录可以使 ...

  8. iOS tableview上放textfield

    用UITableViewController就可以了,处理键盘弹出和消失的代码已经封装在UITableViewController里了.

  9. sublime3095-注册码下载安装

    链接:http://pan.baidu.com/s/1hqejFKS 下载地址:下载 提取密码:egh5 ----- BEGIN LICENSE ----- Andrew Weber Single U ...

  10. freemarker 判断写法

    1.if条件写法:如果data非空则输出:test<#if data?? >test</#if> 2.为空则输出 <#if !(data??) > test < ...