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 ...
随机推荐
- (转)RabbitMQ学习之spring整合发送同步消息
http://blog.csdn.net/zhu_tianwei/article/details/40890543 以下实现使用Exchange类型为DirectExchange. routingke ...
- 通过nvm 切换 npm 版本
通过 nvm-windows 更新 npm 1.先安装 nvm-windows .成功后可在命令窗口 输入nvm 查看到 nvm的版本号. 2..在命令窗口输入 nvm list,查看当前使用的 no ...
- CorelDRAW快速制作绚丽的彩色透明心形
今天小编分享给小伙伴们用CorelDRAW打造绚丽的彩色透明心形.主要使用完美形状组中的心形造型制作出心形图案,经过对图形的模糊操作,再经过图框精确剪裁,最后添加一个彩虹渐变色实现绚丽的彩色透明效果. ...
- IT级别
IT领袖:年入过亿(例如任正非.马化腾.李彦宏.丁磊.马云等,包括期权股票以及投资理财等收入.) IT大哥:年入千万(级别次于以上几位大佬的公司老板,不缺钱,普遍对上一条里的人物羡慕嫉妒恨.) IT精 ...
- Mysql5.7安装过程----win10
---恢复内容开始--- 1.Mysql官网:https://www.mysql.com/downloads/ 有两种下载方式:msi和zip压缩包 2.我下载的是zip压缩包,选择mysql com ...
- Java启动问题-Application Server was not connected before run configuration stop, reason: Unable to ping server at localhost:1099
环境一直跑的挺好的,突然报这么一个错误,百思不得其解. 网上查询之后才想起来,自己当时为了IE能运行浪潮服务器的远程console,将环境变量里面的java换成了32位版本的. 修改jre版本与环境变 ...
- cogs 1164. 跑步
1164. 跑步 ★ 输入文件:runa.in 输出文件:runa.out 简单对比时间限制:1 s 内存限制:128 MB [题目描述] 路人甲准备跑N (5≤N≤500)圈来锻炼自 ...
- Python Study (05)装饰器
装饰器(decorator)是一种高级Python语法.装饰器可以对一个函数.方法或者类进行加工.在Python中,我们有多种方法对函数和类进行加工,比如在Python闭包中,我们见到函数对象作为某一 ...
- POJ 1811
使用Pollard_rho算法就可以过了 #include <iostream> #include <cstdio> #include <algorithm> #i ...
- HBase使用flush命令之后存储的位置
HBase使用flush命令之后存储的位置 根据系统安装位置的不一样而不一样,当前是在: hadoop fs -ls /apps/hbase/data/data/default/t1 下面: 使用ha ...