UVa 11729 - Commando War
【题目翻译】:

题目分析:因为任务是可以并行的执行,所以直觉上是花费时间长的任务优先去部署。但是这到题目还给你交待任务的时间,所以容易让人想多了。
不管有没有交待任务的时间,对于任务x和y,只可能有两种情况。x在y之前结束,和x在y之后结束。这里讨论x在y之前完成。
未交换x和y的位置时,完成时间为:B[x] + B[y] + J[y]
交换h和y位置之后,完成时间为:B[y] + B[x] + J[x]
如果J[y] 大于J[x],那么交换后,时间变短了,所以应该将y放在x之前执行。另一种情况也类似。
这样证明以后就可以大胆的用贪心策略了。
#include<Cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct People
{
int b,j;
} p[1005];
int cmp(People a,People b)
{
return a.j>b.j;
}
int main()
{
int n,cas=0;
while(scanf("%d",&n)!=EOF&&n)
{
cas++;
for(int i=0; i<n; i++)
scanf("%d %d",&p[i].b,&p[i].j);
sort(p,p+n,cmp);
int sum=0,ans=0;
for(int i=0; i<n; i++)
{
sum+=p[i].b;
ans=max(ans,sum+p[i].j);
}
printf("Case %d: %d\n",cas,ans);
}
return 0;
}
UVa 11729 - Commando War的更多相关文章
- 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 ...
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
- [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 突击战
你有 n 个部下,每个部下需要完成一个任务.第 i 个部下需要你花 Bi 分钟交待任务,然后他会立刻独立地.无间断地执行 Ji 分钟后完成任务.你需要选择交待任务的顺序,使得所有任务尽早执行完毕(即最 ...
- UVa 11729 Commando War 【贪心】
题意:有n个部下,交待每个部下完成他相应的任务需要bi的时间,然后完成这项任务需要ji的时间, 选择交待任务的顺序,使得总的花费的时间最少 因为不管怎么样,交待所需要的n*bi的时间都是要花费的, 然 ...
- Commando War
Commando War“Waiting for orders we held in the wood, word from the front never cameBy evening the so ...
- cogs 1446. [Commando War,Uva 11729]突击战
1446. [Commando War,Uva 11729]突击战 ★ 输入文件:commando.in 输出文件:commando.out 简单对比时间限制:1 s 内存限制:64 ...
随机推荐
- 利用电话管理器TelephonyManager获取网络和SIM卡信息
import java.util.ArrayList;import java.util.HashMap;import java.util.Map; import android.os.Bundle;i ...
- 利用LM神经网络和决策树去分类
# -*- coding: utf-8 -*- import pandas as pd from scipy.interpolate import lagrange from matplotlib i ...
- Elasticsearch Java Api--DeleteByQuery
一.安装插件 要删除某个索引的一个type下的所有文档,相当于关系型数据库中的清空表操作.查阅了一些资料可以通过Delete-by-Query插件删除,首先使用插件管理器安装Delete-by-Que ...
- 在phpmyadmin中执行sql语句出现的错误:Unknown storage engine 'InnoDB'
在phpmyadmin中执行sql语句出现的错误:Unknown storage engine 'InnoDB' 解决方法:解决方法: 1.关闭MySQL数据库 2 ...
- 使用eclipse创建在myeclipse中运行的web工程
今天在跟随慕课网学习java时,遇到课程中老师使用Myeclipse,我用的是eclipse,那么就使用eclipse创建在Myeclipse项目 参考: 如何在Eclipse配置Tomcat服务器 ...
- 黑马程序员——C语言基础语法 关键字 标识符 注释 数据及数据类型
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (一下内容是对黑马苹果入学视频的个人知识点总结) (一)C语言简单介绍 (1)C语言程序是由函数组成的任何C语言程序都是由一 ...
- Linux登陆和欢迎信息修改
edit file: /etc/issue,/etc/motd 这样还改不了,生成的脚本在目录/etc/update-motd.d/中: 假如要打开一个文本文件,可以修改10-help-text: ( ...
- 传Windows 9预览版今秋发布
据ZDNet长期关注微软动态的资深人士玛丽•乔•弗利(Mary Jo Foley)称,Windows 9预览版将会在9月或者10月推出.按照这一进度,代号为“Threshold’”的Windows 9 ...
- JS 代理模式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- js 中 setInterval 的返回值问题
var i = 0; var timer = setInterval(function() { i++ console.log(i); //alert(1); }, 2000); alert( typ ...