51 nod 1099 任务执行顺序(贪心)
来源:互联网 发布:iprint打印监控软件 编辑:程序博客网 时间:2024/05/20 15:40
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099
思路:贪心法,剩余空间最大的活动安排在前面。。即 r-o最大 的排前面。。
#include<iostream>#include<cstring>#include<stdio.h>#include<algorithm>#define maxn 100005using namespace std;struct node{ int r,o;};node n[maxn];bool cmp(node a,node b){ return a.r-a.o>b.r-b.o;}int main(){ long long n1,sum=0,sum1=0; scanf("%lld",&n1); for(int x=0;x<n1;x++) scanf("%lld%lld",&n[x].r,&n[x].o); sort(n,n+n1,cmp); for(int x=0;x<n1;x++) { if(sum<=sum1+n[x].r) sum=sum1+n[x].r; sum1+=n[x].o; } printf("%lld\n",sum);}
阅读全文
0 0
- 51nod 1099:任务执行顺序 贪心
- 51nod 1099:任务执行顺序 贪心
- 51nod 1099 任务执行顺序【贪心】
- 51nod 1099 任务执行顺序(贪心)
- 51nod 1099 任务执行顺序 贪心
- 51nod 1099 任务执行顺序(贪心)
- 51nod 1099 任务执行顺序(贪心)
- 51nod 1099 任务执行顺序(贪心)
- 51 nod 1099 任务执行顺序(贪心)
- 51nod 任务执行顺序 贪心
- 51nod oj 1099 任务执行顺序 【贪心】
- 51nod 1099 任务执行顺序 贪心的构造方法
- 51NOD 贪心教程入门 任务执行顺序
- 51NOD 1099 任务执行顺序
- 51 nod 1099 任务执行顺序
- 51nod 1099 任务执行顺序
- 51nod 1099 任务执行顺序
- 51Nod 1099 任务执行顺序
- javascript 简易时钟
- 2166 中位数
- Feign常见的坑总结
- 8-IO库
- Hadoop运行时JAVA_HOME is not set问题
- 51 nod 1099 任务执行顺序(贪心)
- js中构造函数创建对象加不加new的问题
- java协变,逆变,不可变
- Windows下Anaconda的安装和使用--转自CSDN
- Qt的插件机制
- Kafka分区机制介绍与示例
- 2168 开关
- python学习笔记.4创建数值列表
- Wikiwand——更酷的wiki打开方式