首页 技术 正文
技术 2022年11月6日
0 收藏 313 点赞 479 浏览 775 个字

[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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903