UVa 11729 Commando War 【贪心】
题意:有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 【贪心】的更多相关文章
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- 贪心 UVA 11729 Commando War
题目传送门 /* 贪心:按照执行时间长的优先来排序 */ #include <cstdio> #include <algorithm> #include <iostrea ...
- 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 ...
- [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 ...
- UVa 11729 - Commando War
[题目翻译]: 题目分析:因为任务是可以并行的执行,所以直觉上是花费时间长的任务优先去部署.但是这到题目还给你交待任务的时间,所以容易让人想多了. 不管有没有交待任务的时间,对于任务x和y,只可能有两 ...
- UVa 11729 Commando War 突击战
你有 n 个部下,每个部下需要完成一个任务.第 i 个部下需要你花 Bi 分钟交待任务,然后他会立刻独立地.无间断地执行 Ji 分钟后完成任务.你需要选择交待任务的顺序,使得所有任务尽早执行完毕(即最 ...
- cogs 1446. [Commando War,Uva 11729]突击战
1446. [Commando War,Uva 11729]突击战 ★ 输入文件:commando.in 输出文件:commando.out 简单对比时间限制:1 s 内存限制:64 ...
- Commando War
Commando War“Waiting for orders we held in the wood, word from the front never cameBy evening the so ...
随机推荐
- 03--SQLtie三言两语SQLtie链接(join)
本文将从连接的理论和语法讲起,结合具体的例子,详细分析 SQL 连接. 之前对数据库的连接操作似懂非懂,大概知道是什么东西,但是面试笔试的时候被虐成渣,讲不清连接到底是什么.吃一堑,长一智.这就是所谓 ...
- vc++实例创建简单窗体
#include<windows.h>#include<stdio.h>LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,WPAR ...
- 路飞学城Python-Day152
爬取搜狗首页页面数据 import urllib.request # 1.指定url url = r'https://www.sogou.com/' # 2.发起请求 # urlopen()参数内部可 ...
- echarts示例
将做过的echarts图表通过示例形式展示,便于以后使用,基于vue ,echarts,leancloud实现 github源码地址:https://github.com/707293891/echa ...
- MySQL 表与表之间建立关系
引子:如下图是一张非常寻常的表格,在以前的工作中实常会制作类似的表格,但是今天的数据库内容,将我之前这种传统的制表思路上升了一个层次: 今天核心的内容就是怎样让表与表之间产生关系,在思考这个问题的时候 ...
- 天使轮 A轮 B轮 上市...等名词解释
看到一篇漫画解释的很形象:
- Hadoop安装和使用
1.安装 1.1.下载hadoop-2.5.1.tar.gz 1.2.解压至安装目录 tar -zxv -f hadoop-2.5.1.tar.gz -C ../soft/ 1.3.配置hadoop相 ...
- linux chattr用法
在linux中,我们有的时候发现linux无法删除一个文件或者目录. huskiesir第一次遇见这个问题还是在一次服务器被不法分子入侵之后的事情,我就发现某个进程很多,根据进程的名字,我搜索关键字找 ...
- vim+astyle安装使用
astyle下载安装 wget https://sourceforge.net/projects/astyle/files/astyle/astyle%203.1/astyle_3.1_linux.t ...
- NOIP2018提高组省一冲奖班模测训练(五)
NOIP2018提高组省一冲奖班模测训练(五) http://www.51nod.com/Contest/ContestDescription.html#!#contestId=79 今天有点浪…… ...