51Nod 1099 任务执行顺序
来源:互联网 发布:ubuntu黑客帝国屏保 编辑:程序博客网 时间:2024/04/28 00:18
有N个任务需要执行,第i个任务计算时占R[i]个空间,而后会释放一部分,最后储存计算结果需要占据O[i]个空间(O[i] < R[i])。
例如:执行需要5个空间,最后储存需要2个空间。给出N个任务执行和存储所需的空间,问执行所有任务最少需要多少空间。
Input
第1行:1个数N,表示任务的数量。(2 <= N <= 100000)第2 - N + 1行:每行2个数R[i]和O[i],分别为执行所需的空间和存储所需的空间。(1 <= O[i] < R[i] <= 10000)
Output
输出执行所有任务所需要的最少空间。
Input示例
2014 12 111 320 47 56 520 719 89 420 1018 1112 613 1214 915 216 1517 1519 1320 220 1
Output示例
135
分析:排序的时候要将 oper-store 这个差值大的放前面,让它先执行,这样就能取到最小值。
#include <stdio.h>#include <algorithm>using namespace std;struct node{int store;int oper;}a[100005];bool cmp(node n1, node n2){ return n1.oper - n1.store > n2.oper - n2.store;}int main(){ int n;int sum = 0;scanf("%d", &n); sum = 0;for (int i = 0; i < n; i++){scanf("%d%d", &a[i].oper, &a[i].store);sum += a[i].store;}sort(a, a + n, cmp); int already = 0;int temp;for (int i = 0; i < n; i++){temp = already + a[i].oper;already += a[i].store;if(temp > sum) sum = temp;}printf("%d\n", sum);return 0;}
0 0
- 51nod 1099:任务执行顺序 贪心
- 51NOD 1099 任务执行顺序
- 51 nod 1099 任务执行顺序
- 51nod 1099:任务执行顺序 贪心
- 51nod 1099 任务执行顺序
- 51nod 1099 任务执行顺序
- 51Nod 1099 任务执行顺序
- 51nod 1099 任务执行顺序【贪心】
- 51nod-1099 任务执行顺序
- 【51nod】1099 任务执行顺序
- 51nod 1099 任务执行顺序
- 51nod 1099 任务执行顺序
- 51nod 1099 任务执行顺序 ACM
- 51nod 1099 任务执行顺序(贪心)
- 51nod 1099 任务执行顺序 贪心
- 51nod 1099 任务执行顺序(贪心)
- 51nod--任务执行顺序
- 51nod-任务执行顺序
- Python 浅拷贝 深拷贝 及引用机制
- 利用union判断系统的大小端
- 表空间追加
- 17967 大师姐唱K的固有结界
- gulp+webpack+angular1的一点小经验(第二部分webpack包起来的angular1)
- 51Nod 1099 任务执行顺序
- 读《必然》的总结与感悟
- 正则表达式(regular expression)——学习笔记
- windows下theano安装教程
- Android Multimedia框架总结(二十二)MediaCodec中C++中创建到start过程及状态变换
- linux查看所有串口和usb设备方法
- css 设置浏览器滚动条
- Java学习笔记 --- IO理解总结
- java多线程笔记1