题意:有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. bootstrap modal 一闪

    原因可能是因为bootstrap.min.js(bootstrap.js) 和modal.js重复引用导致的,而且重复引用还会引致bootstrap的js事件失效.

  2. Swift中self和Self

    Self相当于oc中的instance 是什么 相信大家都知道self这个关键字的具体作用,它跟OC里的self基本一样.但是对于Self来说...(WTF,这是什么东西) 当你用错Self的时候编译 ...

  3. java中String和int的互相转化

    1. String 转 int 方式1:Integer.parseInt(); 方式2: Integer.valueOf(myStr).intValue(); 2.  int 转String 方式1: ...

  4. js中浏览器兼容startsWith 、endsWith 函数

    在做js开发的时候用到了startsWith函数时,发现各个浏览器不兼容问题,因为对开发来说,chrome浏览器最好用,就一直在chrome浏览器中使用这两个函数没有任何问题,但在ie浏览器访问就直接 ...

  5. vue 函数配置项watch以及函数 $watch 源码分享

    Vue双向榜单的原理     大家都知道Vue采用的是MVVM的设计模式,采用数据驱动实现双向绑定,不明白双向绑定原理的需要先补充双向绑定的知识,在watch的处理中将运用到Vue的双向榜单原理,所以 ...

  6. HDU 1021 Fibonacci Again( 同余水 )

    链接:传送门 题意:现在给出 Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).问第 n 项能不能整除 ...

  7. Problem 1

    Problem 1 # Problem_1.py """ If we list all the natural numbers below 10 that are mul ...

  8. NYIST 119 士兵杀敌(三)

    士兵杀敌(三)时间限制:2000 ms | 内存限制:65535 KB难度:5 描述南将军统率着N个士兵,士兵分别编号为1~N,南将军经常爱拿某一段编号内杀敌数最高的人与杀敌数最低的人进行比较,计算出 ...

  9. Qt Quick 之 QML 与 C++ 混合编程具体解释

    Qt Quick 技术的引入.使得你能够高速构建 UI ,具有动画.各种绚丽效果的 UI 都不在话下.但它不是万能的.也有非常多局限性,原来 Qt 的一些技术,比方低阶的网络编程如 QTcpSocke ...

  10. Android 开发最佳实践

    原文地址:https://github.com/futurice/android-best-practices/blob/master/translations/Chinese/README.cn.m ...