题目大意

你有n个部下,每个部下需要完成一项任务。第i个部下需要你花Bj分钟交代任务,然后他就会立刻独立地、无间断地执行Ji分钟后完成任务。你需要选择交代任务的顺序,使得所有任务尽早执行完毕(即最后一个执行完的任务应尽早结束)。注意,不能同时给两个部下交代任务,但部下们可以同时执行他们各自的任务。

Solution

还是考虑贪心对吧,我们觉得如果一个人要执行的时间越长肯定就先安排,这个是可以证明的.

现在有两个士兵,他们的值分别为:{b1,j1},{b2,j2}(假设j1>j2)

那么我们分别安排一下顺序就是:

max(b1+j1,b1+b2+j2)

max(b2+j2,b1+b2+j1)

因为j1>j2,所以下面的式子恒大于等于上面的式子

#include<bits/stdc++.h>
using namespace std;
const int N=1010;
struct node{
int b,j;
bool operator<(const node q)const{
return j>q.j;
}
}a[N];
int main(){
int n,i,Case=0;
while(scanf("%d",&n)==1 && n){
Case++;
for(i=0;i<n;i++)
scanf("%d%d",&a[i].b,&a[i].j);
sort(a,a+n);int nowTime=0,ans=0;
for(i=0;i<n;i++){
nowTime+=a[i].b;
ans=max(ans,nowTime+a[i].j);
}
printf("Case %d: %d\n",Case,ans);
}
return 0;
}

【题解】 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

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

  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. C++Primer笔记-----day01

    =======================================================day01======================================== ...

  2. Unity Mecanim 动画系统

    1. Animator 组件 Controller:使用的Animator Controller文件. Avatar:使用的骨骼文件. Apply Root Motion:绑定该组件的GameObje ...

  3. <转>Linux环境进程间通信(五): 共享内存(下)

    http://www.ibm.com/developerworks/cn/linux/l-ipc/part5/index2.html 系统调用mmap()通过映射一个普通文件实现共享内存.系统V则是通 ...

  4. [转]字符集、字符编码、XML中的中文编码

    字符集.字符编码.XML中的中文编码 作为程序员的你是不是对于ASCII .UNICODE.GB2321.UTF-7.UTF-8等等不时出现在你面前的这些有着奇怪意义的词感到很讨厌呢,是不是总觉得好象 ...

  5. java 蓝桥杯基础练习 01字串 进制转换

    问题描述 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能.它们的前几个是: 请按从小到大的顺序输出这32种01串. 输入格式 本试题没有输入. 输出格式 输出32行,按从小到大的顺 ...

  6. react-native init安装指定版本的react-native

    C:\Users\ZHONGZHENHUA\imooc_gp\index.js index.js /** @format */ import React,{ Component } from 'rea ...

  7. ubuntu eclipse opencv环境配置

    项目——Properties——C/C++ Build——Settings 配置包含目录: GCC C++ Compiler   ——Includes /usr/include /usr/local/ ...

  8. Java 依赖注入标准(JSR-330)简介

    作者:88250 ,Vanessa 时间:2009 年 11 月 19 日      Java 依赖注入标准(JSR-330,Dependency Injection for Java)1.0 规范已 ...

  9. devcloud 基础架构

           

  10. Mosquitto 单向SSL配置

    Mosquitto 单向SSL配置 摘自:https://blog.csdn.net/a_bcd_123/article/details/70167833 2017年04月14日 06:56:06 s ...