[USACO08NOV]Time Management

题目大意:

有\(n(n\le1000)\)个任务,同一时间只能进行一个任务。每个任务有一个进行时间\(t_i\)和一个截止时间\(s_i\),你可以任意交换这些任务的顺序。问开始第一个任务的时间最晚是多少。

思路:

按照\(s_i\)从大到小排序然后贪心。

时间复杂度\(\mathcal O(n\log n)\)。

源代码:

#include<cstdio>
#include<cctype>
#include<climits>
#include<algorithm>
#include<functional>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int N=1e3+1;
struct Task {
int t,s;
bool operator > (const Task &rhs) const {
return s>rhs.s;
}
};
Task t[N];
int main() {
const int n=getint();
for(register int i=1;i<=n;i++) {
t[i].t=getint();
t[i].s=getint();
}
std::sort(&t[1],&t[n]+1,std::greater<Task>());
int last=INT_MAX;
for(register int i=1;i<=n;i++) {
last=std::min(last,t[i].s);
last-=t[i].t;
}
printf("%d\n",last>=0?last:-1);
return 0;
}

[USACO08NOV]Time Management的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. [USACO08NOV]时间管理Time Management

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

  8. SQL Server Management Studio 无法修改表,超时时间已到 在操作完成之前超时时

    在修改表时,保存的时候显示:无法修改表,超时时间已到 在操作完成之前超时时间已过或服务器未响应 这是执行时间设置过短的原因,可以修改一下设置便能把执行时间加长,以便有足够的时间执行完修改动作. 在 S ...

  9. Java Business Process Management(业务流程管理) 初识环境搭建

    一.简介 (一)什么是jbpm JBPM,全称是Java Business Process Management(业务流程管理),它是覆盖了业务流程管理.工作流.服务协作等领域的一个开源的.灵活的.易 ...

随机推荐

  1. 【跟我学apache-commons】【四】commons-io的使用

    commons-io是一款处理io流的工具,封装了很多处理io流和文件的方法,可以大大简化我们处理io流和操作文件的代码.从common-io的官方使用文档可以看出,它主要分为工具类.尾端类.行迭代器 ...

  2. Spark记录-实例和运行在Yarn

    #运行实例 #./bin/run-example SparkPi 10   #./bin/spark-shell --master local[2] #./bin/pyspark --master l ...

  3. Google-403-Forbidden

    Author:KillerLegend Date:2014.8.14 From:http://www.cnblogs.com/killerlegend/p/3913554.html www.googl ...

  4. css中实现ul两端的li对齐外面边缘

    其实就是设置ul的宽度大一些就好

  5. php设计模式之注册树模式

    什么是注册树模式?[全局共享和交换对象] 注册树模式当然也叫注册模式,注册器模式.注册树模式通过将对象实例注册到一棵全局的对象树上,需要的时候从对象树上采摘的模式设计方法.   这让我想起了小时候买糖 ...

  6. 使用WebHelper调用Asp.net WebAPI

    1.WebHelper using System; using System.Collections.Generic; using System.Collections.Specialized; us ...

  7. perl6 中将 字符串 转成十六进制

    say Blob.new('abcde'.encode('utf8')).unpack("H*"); say '0x'~'abcde'.encode('utf8').unpack( ...

  8. win10 无法打开 APICloud Studio 2 的解决方案

    坑爹. 新搭建了系统   apicloud studio2  打开无反应 无任何报错提示 双击没有方案.弄了一天 最后搞定. . 百度搜索  win10    null.sys 替换进去 C:/Win ...

  9. HTTPS-加密SSL证书

    从第一部分HTTP工作原理中,我们可以了解到HTTPS核心的一个部分是数据传输之前的握手,握手过程中确定了数据加密的密码.在握手过程中,网站会向浏览器发送SSL证书,SSL证书和我们日常用的身份证类似 ...

  10. django startproject xxx:报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 13: ordinal not in range(128)

    django startproject xxx:报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 13: o ...