题意:有n个部下,交待每个部下完成他相应的任务需要bi的时间,然后完成这项任务需要ji的时间,

选择交待任务的顺序,使得总的花费的时间最少

因为不管怎么样,交待所需要的n*bi的时间都是要花费的,

然后就让完成任务需要的时间长的人先做,就将j按降序排,更新每完成一个人的任务所花费的时间

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int n;
struct node{
int b,q;
} a[maxn]; int cmp(node n1,node n2){
return n1.q > n2.q;
} int main(){
int kase = ;
while(scanf("%d",&n) != EOF && n){
for(int i=;i<=n;i++) scanf("%d %d",&a[i].b,&a[i].q);
sort(a+,a+n+,cmp); int beg = ,end = ,ans = ; for(int i = ;i <= n;i++){
beg += a[i].b;
if(beg + a[i].q >= end) end = beg + a[i].q; // printf("i = %d beg = %d end = %d\n",i,beg,end);
}
printf("Case %d: %d\n",++kase,max(beg,end));
}
return ;
}

UVa 11729 Commando War 【贪心】的更多相关文章

  1. UVa 11729 - Commando War(贪心)

    "Waiting for orders we held in the wood, word from the front never came By evening the sound of ...

  2. Uva 11729 Commando War (简单贪心)

    Uva 11729  Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...

  3. 贪心 UVA 11729 Commando War

    题目传送门 /* 贪心:按照执行时间长的优先来排序 */ #include <cstdio> #include <algorithm> #include <iostrea ...

  4. UVA 11729 - Commando War(贪心 相邻交换法)

    Commando War There is a war and it doesn't look very promising for your country. Now it's time to ac ...

  5. [ACM_水题] UVA 11729 Commando War [不可同时交代任务 可同时执行 最短完成全部时间 贪心]

    There is a war and it doesn't look very promising for your country. Now it's time to act. You have a ...

  6. UVa 11729 - Commando War

    [题目翻译]: 题目分析:因为任务是可以并行的执行,所以直觉上是花费时间长的任务优先去部署.但是这到题目还给你交待任务的时间,所以容易让人想多了. 不管有没有交待任务的时间,对于任务x和y,只可能有两 ...

  7. UVa 11729 Commando War 突击战

    你有 n 个部下,每个部下需要完成一个任务.第 i 个部下需要你花 Bi 分钟交待任务,然后他会立刻独立地.无间断地执行 Ji 分钟后完成任务.你需要选择交待任务的顺序,使得所有任务尽早执行完毕(即最 ...

  8. cogs 1446. [Commando War,Uva 11729]突击战

    1446. [Commando War,Uva 11729]突击战 ★   输入文件:commando.in   输出文件:commando.out   简单对比时间限制:1 s   内存限制:64 ...

  9. Commando War

    Commando War“Waiting for orders we held in the wood, word from the front never cameBy evening the so ...

随机推荐

  1. C# 1.将整个文件夹复制到目标文件夹中 2.将指定文件复制到指定目标文件夹中

    ].Items.Clear(); string filePath = Application.StartupPath; string sourcePath = Path.Combine(filePat ...

  2. word2016如何英汉互译

    1.如果是一篇英文文档且是pdf格式,可以用word2016打开直接转化成了word,就算不是会员也可以的,在此附上16版的光盘安装包,可以百度自行下载 (链接:https://pan.baidu.c ...

  3. 路飞学城Python-Day137

    django项目二 个人博客系统 github地址:https://github.com/pandaboy1123/cnblog

  4. C语言提高 (4) 第四天 数组与数组作为参数时的数组指针

    1昨日回顾 const int 和 int const是一样的 const char *p;值不变 char * const p; 指针不能变 编译器对参数的退化: 第三种模型: 三级指针 三级指针局 ...

  5. jquery.lazyload滚动不起作用

    昨天同事在开发图片懒加载功能时用到了lazyload,使用相当标准,然而结果却不如人意,在滚动时未能起作用.引用https://cdn.bootcss.com/jquery_lazyload/1.9. ...

  6. 自动化测试之firebug、firepath、IDE的使用

    1firebug安装-firefox添加组件-firebug 如图 firepath依赖于firebug 展示路径用,安装和firebug一样

  7. jQuery.extend()的合并对象功能

    jQuery.extend( [ deep ], target, object1, [ objectN ] )合并对象到第一个对象 //deep为boolean类型,其它参数为object类型 var ...

  8. [poj 3666] Making the Grade (离散化 线性dp)

    今天的第一题(/ω\)! Description A straight dirt road connects two fields on FJ's farm, but it changes eleva ...

  9. mybatis入门截图总结

    原生态jdbc存在的问题 ------------------- ----------------------- ------- 环境的搭建 ----------------------------- ...

  10. OA项目知识总结

    struts文件配置 --------------------------------------------------------- 配置c3po链接池 --------------------- ...