相邻两个士兵交换顺序,不会对其他的有所影响,贪心考虑两两之间交换策略即可。

sort大法好。印象中这类排序题里有一种会卡sort,只能冒泡排序,然而到现在还没有遇到

 /**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct node{
int b;
int j;
};
int cmp(const node a,const node b){
return a.j>b.j;
}
int main(){
int n,b,j;
int case_count=;
while(scanf("%d",&n)!=EOF &&n){
struct node sod[];
int i;
for(i=;i<=n;i++)
scanf("%d%d",&sod[i].b,&sod[i].j);
sort(sod+,sod+n+,cmp);
int s=;
int ans=;
for(i=;i<=n;i++){
s+=sod[i].b;
ans=max(ans,s+sod[i].j);
}
printf("Case %d: %d\n",case_count++,ans);
} return ; }

Uva11729 Commando War的更多相关文章

  1. uva----11729 Commando war (突击战争)

    G Commando War Input: Standard Input Output: Standard Output “Waiting for orders we held in the wood ...

  2. 【题解】 UVa11729 Commando War

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

  3. uva11729 - Commando War(贪心)

    贪心法,执行任务的时间J越长的应该越先交待.可以用相邻交换法证明正确性.其实对于两个人,要让总时间最短,就要让同一时间干两件事的时间最长. #include<iostream> #incl ...

  4. Commando War

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

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

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

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

  7. 贪心 UVA 11729 Commando War

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

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

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

  9. 【贪心】【Uva11729】 Commando War

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

随机推荐

  1. IO流的练习 —— 创建用户注册、登陆案例

    把上次用集合做的时候的分析拿出来 需求: 用户登录注册案例 按照如下操作,可以让我们更符合面向对象思想: A:这个案例有哪些类 B:每个类中又有哪些东西 C:类与类之间的关系 分析: A:这个案例有哪 ...

  2. 关于OAuth2.0的文章收集

    http://blog.csdn.net/seccloud/article/details/8192707

  3. yum报错:Error: xz compression not available

    测试服务器(centos6.5)经过一段时间的折腾,有一天在上面进行yum操作时突然出现下面的报错: Error: xz compression not available 最后经过一番排查,发现原因 ...

  4. Memcached通用类(基于enyim.com Memcached Client)

    一.如果用官方提供的方法,在web.config里面配置好了各个参数和服务器IP.如下图: <?xml version="1.0"?> <configuratio ...

  5. python数字图像处理(14):高级滤波

    本文提供更多更强大的滤波方法,这些方法放在filters.rank子模块内. 这些方法需要用户自己设定滤波器的形状和大小,因此需要导入morphology模块来设定. 1.autolevel 这个词在 ...

  6. initializer for conditional binding must have optional type not AVAudioPlayer

    if let buttonBeep = self.setupAudioPlayerWithFile("ButtonTap", type: "wav") {    ...

  7. IOS开发之——意见反馈UITextView的使用+不能输入字符输入

    @interface DMFeedbackViewController ()<UITextViewDelegate,UIAlertViewDelegate>@property (nonat ...

  8. .NET MVC控制器向视图传递数据的四种方式

    .NET MVC控制器向视图传递数据的四种方式: 1.ViewBag  ViewBag.Mvc="mvc"; 2.ViewData ViewBag["Mvc"] ...

  9. powerdesigner 绘制表关系和导出sql

    1.生成图(A图,B图) 2.创建关系(palette工具栏里有个线条,主表子表关系连接即可,拖动是由顺序的,一对多即从A表往B表连接) 3.这里小说一下   一开始是CDM模式,可以在软件最顶层看到 ...

  10. 第七章 new的三步曲

    这章是本系列文章的重点,这章揭示了js对象的真正本质 看下面的事例 var a = new b(); 等价于 ①var a={}; ②a.__proto__=b.prototype; ③b.call( ...