UVA 11729 - Commando War
来源:互联网 发布:c语言中数据类型长度 编辑:程序博客网 时间:2024/05/21 17:02
贪心
首先按执行时间排序,然后维护一个变量maxJobTimeLeft,表示最大的任务剩余时间,累加所有的分配时间,再加上最后的最大任务剩余时间就是答案
#include <iostream>#include <memory.h>#include <algorithm>#include <cstdio>using namespace std;#define MAX 1010struct node{int b,j;bool operator<(const node & rhs)const{return j>rhs.j;}}soldiers[MAX];int n;int main(){int cas=1;while (scanf("%d",&n)&&n){int cost=0,maxJobTimeLeft=0;for(int i=0;i<n;++i)scanf("%d %d",&soldiers[i].b,&soldiers[i].j);sort(soldiers,soldiers+n);for (int i=0;i<n;++i){cost+=soldiers[i].b;maxJobTimeLeft-=soldiers[i].b;if(soldiers[i].j>maxJobTimeLeft)maxJobTimeLeft=soldiers[i].j;}printf("Case %d: %d\n",cas++,cost+maxJobTimeLeft);}}
- uva --11729-- Commando War
- UVa 11729 Commando War
- uva - 11729 - Commando War
- UVA 11729 - Commando War
- uva 11729 - Commando War
- Uva-11729-Commando War
- UVA 11729 - Commando War
- UVA 11729 Commando War
- UVA 11729 - Commando War
- UVA 11729 Commando War
- UVA 11729 - Commando War
- Commando War, UVa 11729
- UVa 11729 - Commando War
- UVA 11729 Commando War
- uva 11729 Commando War
- Uva 11729 Commando War
- uva 11729 Commando War
- UVA - 11729 Commando War
- HDU4510:小Q系列故事——为什么时光不能倒流
- C语言实现链表
- 调试jar包里的源文件及打印log
- VS2010程序打包操作(超详细的)
- C#中发送HttpPost请求来调用WebService
- UVA 11729 - Commando War
- 【linux问答】linux & win 压缩解压缩
- 宿舍共享上网教程
- C++文件读写
- 字符反转
- Nearest-Neighbor Classifier紧邻算法分类器(一)
- 通信类学生投稿,查资料必读
- c++成员函数的数组
- 5.跟我一起学建站之Spring MVC Hello world xml版