题意:有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. 洛谷P3275 [SCOI2011]糖果_差分约束_判负环

    Code: #include<cstdio> #include<queue> #include<algorithm> using namespace std; co ...

  2. 强大的JQuery链式操作风格

    实例代码 <style type="text/css"> #menu {width: 300px;} .has_children {background:#555;co ...

  3. Python笔记9-----不等长列表转化成DataFrame

    1.不同长度的列表合并成DataFrame. 法1: ntest=['a','b'] ltest=[[1,2],[4,5,6]] 先变成等长的列表:(a:1),(a:2),(b:4),(b:5),(b ...

  4. Python数据分析2------数据探索

    一.数据探索 数据探索的目的:及早发现数据的一些简单规律或特征 数据清洗的目的:留下可靠数据,避免脏数据的干扰. 两者没有严格的先后顺序,经常在一个阶段进行. 分为: (1)数据质量分析(跟数据清洗密 ...

  5. C++进阶 STL(1) 第一天 [容器,算法,迭代器] string容器 vector容器 deque容器

    课程大纲 02实现基本原理 容器,算法,迭代器 教室:容器 人:元素 教室对于楼:容器 序列式容器: 容器元素在容器中的位置是由进入容器的时间和地点来决定 序列式容器 关联式容器: 教室中 按年龄排座 ...

  6. Project Euler 32 Pandigital products

    题意:找出所有形如 39 × 186 = 7254 这种,由 1 - 9,9个数字构成的等式的和,注意相同的积不计算两次 思路:如下面两种方法 方法一:暴力枚举间断点 /*************** ...

  7. 03.IO读写-1.IO介绍

    1 文件操作介绍 in: 输入,读入.从硬盘中读到内存 out: 输出.从内存写到硬盘 文件的作用: 数据存储 2 文件的打开与关闭 2.1 打开文件 在Python,使用open函数,可以打开一个已 ...

  8. Linux设备驱动--块设备(一)之概念和框架(转)

    基本概念   块设备(blockdevice) --- 是一种具有一定结构的随机存取设备,对这种设备的读写是按块进行的,他使用缓冲区来存放暂时的数据,待条件成熟后,从缓存一次性写入设备或者从设备一次性 ...

  9. 最简单的tomcat安装部署

    [安装环境] 适用于所有Linux操作系统,本人使用的是Centos 7.4 [安装] 浏览器登陆到tomcat官网 http://tomcat.apache.org/ 点击左侧需要下载的版本 右键图 ...

  10. 【CodeForces 271D】Good Substrings

    [链接] 我是链接,点我呀:) [题意] [题解] 字典树 我们可以两重循环(i,j) 来枚举所有的子串 即i=1,j=1,2,3... i=2,j = 2,3,4,.. 于是我们在i变化的时候(就是 ...