【题目翻译】:

题目分析:因为任务是可以并行的执行,所以直觉上是花费时间长的任务优先去部署。但是这到题目还给你交待任务的时间,所以容易让人想多了。

不管有没有交待任务的时间,对于任务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的更多相关文章

  1. Uva 11729 Commando War (简单贪心)

    Uva 11729  Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...

  2. 贪心 UVA 11729 Commando War

    题目传送门 /* 贪心:按照执行时间长的优先来排序 */ #include <cstdio> #include <algorithm> #include <iostrea ...

  3. 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 ...

  4. UVa 11729 - Commando War(贪心)

    "Waiting for orders we held in the wood, word from the front never came By evening the sound of ...

  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 突击战

    你有 n 个部下,每个部下需要完成一个任务.第 i 个部下需要你花 Bi 分钟交待任务,然后他会立刻独立地.无间断地执行 Ji 分钟后完成任务.你需要选择交待任务的顺序,使得所有任务尽早执行完毕(即最 ...

  7. UVa 11729 Commando War 【贪心】

    题意:有n个部下,交待每个部下完成他相应的任务需要bi的时间,然后完成这项任务需要ji的时间, 选择交待任务的顺序,使得总的花费的时间最少 因为不管怎么样,交待所需要的n*bi的时间都是要花费的, 然 ...

  8. Commando War

    Commando War“Waiting for orders we held in the wood, word from the front never cameBy evening the so ...

  9. cogs 1446. [Commando War,Uva 11729]突击战

    1446. [Commando War,Uva 11729]突击战 ★   输入文件:commando.in   输出文件:commando.out   简单对比时间限制:1 s   内存限制:64 ...

随机推荐

  1. sphinx全文检索功能 | windows下测试 (二)

    sphinx 数据库检索需要对数据库重新生成索引,为自己所用,然后按照拆词匹配

  2. Swift - 自动布局库SnapKit的使用详解3(约束优先级,约束做动画)

    1,约束优先级我们使用SnapKit的时候,还可以定义约束的优先级.这样当约束出现冲突的时候,优先级高的约束覆盖优先级低的约束.具体优先级可以放在约束链的结束处. (1)可以设置如下几种优先级 pri ...

  3. 基础的 Linux 网络命令,你值得拥有

    导读 有抱负的 Linux 系统管理员和 Linux 狂热者必须知道的.最重要的.而且基础的 Linux 网络命令合集.在 It's FOSS 我们并非每天都谈论 Linux 的"命令行方面 ...

  4. POJ 1077 && HDU 1043 Eight A*算法,bfs,康托展开,hash 难度:3

    http://poj.org/problem?id=1077 http://acm.hdu.edu.cn/showproblem.php?pid=1043 X=a[n]*(n-1)!+a[n-1]*( ...

  5. C++封装、继承、多态

    C++封装继承多态总结 面向对象的三个基本特征 面向对象的三个基本特征是:封装.继承.多态.其中,封装可以隐藏实现细节,使得代码模块化:继承可以扩展已存在的代码模块(类):它们的目的都是为了--代码重 ...

  6. hdu 1030 Delta-wave (C++, 0ms, explanatory comments.) 分类: hdoj 2015-06-15 12:21 45人阅读 评论(0) 收藏

    problem description http://acm.hdu.edu.cn/showproblem.php?pid=1030 #include <cstdio> #include ...

  7. 【转发】centos 7安装完后出现please make your choice from '1' ......

    PS:出现以上信息,是要求你阅读或者接收协议: Initial setup of CentOS Linux 7 (core)解决步骤如下: 1,输入[1],按Enter键阅读许可协议,2,输入[2], ...

  8. Python开发入门与实战1-开发环境

    1.搭建Python Django开发环境 1.1.Python运行环境安装 Python官网:http://www.python.org/ Python最新源码,二进制文档,新闻资讯等可以在Pyth ...

  9. SpringMvc 单例

    struts2的controller是多例,是因为其中有modeldriven将比如user 或者其他属性暴露出来,接受属性,特别是继承了actionsupport之后,fielderror的属性也会 ...

  10. ImageLoder配置以及使用(个人阅读使用)

    http://blog.csdn.net/vipzjyno1/article/details/23206387 在gradle添加: compile 'com.nostra13.universalim ...