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

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=+;
struct node
{
int B,J;
}a[maxn];
int n,ans,cas=;
bool cmp(node x,node y)
{
return x.J>y.J;
}
int main()
{
//freopen("in2.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d",&n)==&&n)
{
for(int i=;i<n;i++)
{
scanf("%d%d",&a[i].B,&a[i].J);
}
sort(a,a+n,cmp);
ans=a[].B+a[].J;
int t=a[].B+a[].J;
for(int i=;i<n;i++)
{
t+=a[i].B+a[i].J-a[i-].J;//t表示每一“横条”的用时
ans=max(ans,t); }
printf("Case %d: %d\n",++cas,ans);
}
//fclose(stdin);
//fclose(stdout);
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. UVa 11729 - Commando War(贪心)

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

  3. Uva11729 Commando War

    相邻两个士兵交换顺序,不会对其他的有所影响,贪心考虑两两之间交换策略即可. sort大法好.印象中这类排序题里有一种会卡sort,只能冒泡排序,然而到现在还没有遇到 /**/ #include< ...

  4. 【题解】 UVa11729 Commando War

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

  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. Commando War

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

随机推荐

  1. Traverse the dict in Python

    We usually use the following 2 ways to traverse a dict: 1: for d in dic 2: for d in dic.keys() Which ...

  2. asp.net 利用Response.Filter 获取输出内容, 变更输出内容

    重写 Response.Filter 就可以获取或更新输出到浏览器的内容       资料: https://weblog.west-wind.com/posts/2009/Nov/13/Captur ...

  3. Linux进程优先级查看及修改

    进程cpu资源分配就是指进程的优先权(priority).优先权高的进程有优先执行权利.配置进程优先权对多任务环境的Linux很有用,可以改善系统性能.还可以把进程运行到指定的CPU上,这样一来,把不 ...

  4. VC中添加消息响应函数

    1. 添加消息映射 2. 头文件中添加函数声明 3. 实现文件中添加函数定义

  5. MongoDB的Find详解(一)

    1.指定返回的键 db.[documentName].find ({条件},{键指定}) 数据准备persons.json var persons = [{name:"jim",a ...

  6. centos 下安装python3.6.2

    具体详情: http://www.cnblogs.com/vurtne-lu/p/7068521.html

  7. B-树 C++模板类封装(有图有真相)

    定义: 一棵m阶B-树是拥有以下性质的多路查找树: 1.非叶子结点的根结点至少拥有两棵子树: 2.每一个非根且非叶子的结点含有k-1个关键字以及k个子树,其中⌈m/2⌉≤k≤m: 3.每一个叶子结点都 ...

  8. 20165101 实验一 Java开发环境的熟悉

    #20165103 实验一 Java开发环境的熟悉 实验报告 封面 实验要求 第一部分 1.建立"自己学号exp1"的目录 2.在"自己学号exp1"目录下建立 ...

  9. 进程【TLCL】

    ps命令 ps x 加上 "x" 选项(注意没有开头的 "-" 字符),告诉 ps 命令,展示所有进程,不管它们由什么 终端(如果有的话)控制. 在 TTY 一 ...

  10. SpringMVC中使用ModelAndView遇到的问题

    本文记录我在SpringMVC中使用ModelAndView,添加模型数据到ModelAndView中时遇到的问题: 1.jsp页面用EL表达式来获取值时直接显示EL表达式,JSP不解析EL表达式: ...