Commando War
“Waiting for orders we held in the wood, word from the front never came
By evening the sound of the gunfire was miles away
Ah softly we moved through the shadows, slip away through the trees
Crossing their lines in the mists in the fields on our hands and our knees
And all that I ever, was able to see
The fire in the air, glowing red, silhouetting the smoke on the breeze”
There is a war and it doesn’t look very promising for your country. Now it’s time to act. You have a
commando squad at your disposal and planning an ambush on an important enemy camp located nearby.
You have N soldiers in your squad. In your master-plan, every single soldier has a unique responsibility
and you don’t want any of your soldier to know the plan for other soldiers so that everyone can focus on
his task only. In order to enforce this, you brief every individual soldier about his tasks separately and
just before sending him to the battlefield. You know that every single soldier needs a certain amount
of time to execute his job. You also know very clearly how much time you need to brief every single
soldier. Being anxious to finish the total operation as soon as possible, you need to find an order of
briefing your soldiers that will minimize the time necessary for all the soldiers to complete their tasks.
You may assume that, no soldier has a plan that depends on the tasks of his fellows. In other words,
once a soldier begins a task, he can finish it without the necessity of pausing in between.
Input
There will be multiple test cases in the input file. Every test case starts with an integer N (1 N
1000), denoting the number of soldiers. Each of the following N lines describe a soldier with two integers
B (1 B 10000) & J (1 J 10000). B seconds are needed to brief the soldier while completing
his job needs J seconds. The end of input will be denoted by a case with N = 0. This case should not
be processed.
Output
For each test case, print a line in the format, ‘Case X: Y ’, where X is the case number & Y is the
total number of seconds counted from the start of your first briefing till the completion of all jobs.
Sample Input
32
5
3 2
2 1
33
3
4 4
5 5
0
Universidad de Valladolid OJ: 11729 – Commando War 2/2
Sample Output
Case 1: 8
Case 2: 15

 #include<stdio.h>
#include<algorithm>
using namespace std;
struct plan {
int B , J ;
}a[] ; int n ;
int bri , job ; int cmp (plan a , plan b ) {
return a.J >= b.J ;
}
int main () {
//freopen ("a.txt" , "r" , stdin ) ;
int sum = ;
int minn ;
int cnt = ;
while ( scanf ("%d" , &n ) != EOF , n ) {
sum = ;
for (int i = ; i < n ; i++ ) {
scanf ("%d%d" , &a[i].B , &a[i].J ) ;
sum += a[i].B ;
}
sort (a , a + n , cmp ) ;
/*for (int i = 0 ; i < n ; i++ ) {
printf ("%d " , a[i].J) ;
}
printf ("\n") ; */
job = a[].J ;
//printf ("job=%d\n" , a[0].J ) ;
for ( int i = ; i < n ; i++ ) {
// printf ("%d %d\n" , a[i].B , job ) ;
if ( a[i].B >= job ) {
job = a[i].J ;
}
else {
if ( a[i].B + a[i].J - job < )
job -= a[i].B ;
else
job = a[i].J ;
}
}
//printf ("job = %d\n" , job ) ;
printf ("Case %d: %d\n" , cnt , sum + job ) ;
cnt++ ;
}
return ;
}

先通过J的大小进行排序,然后用 job 来表示超过当前的 sum(B) 长度,最后结果为job+sum(J) (因为至少要花sum(J)的时间)

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(贪心 相邻交换法)

    Commando War There is a war and it doesn't look very promising for your country. Now it's time to ac ...

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

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

  4. 贪心 UVA 11729 Commando War

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

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

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

  6. [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 ...

  7. UVa 11729 - Commando War(贪心)

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

  8. Commando War (贪心)

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

  9. Uva11729 Commando War

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

随机推荐

  1. css兼容性的问题

    https://www.douban.com/note/314793848/ 随意的一个博客ie6的兼容 这个博客比较好 http://blog.csdn.net/chuyuqing/article/ ...

  2. AJAX(二)AJAX框架

    上文(AJAX(一)AJAX的简介和基础)对ajax异步请求服务器做了详细的介绍和基础应用,可以看出,ajax的一些过程是相对不变的.不必要每次发送请求都写一遍发送代码,一些ajax开发人员已经把他们 ...

  3. AngularJS开发指南12:AngularJS的模板,CSS,数据绑定详解

    模板 AngularJS模板是一种声明式的规则.它包含了模型和控制器的信息,最后会被渲染成用户在浏览器中看到的视图.它是静态的DOM,包含HTML,CSS和AngularJS指定的元素和属性.Angu ...

  4. angular-input

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. SDAutolayout图片大小根据数量变化

    只需要在自定义的PhotoContainerView中做一下判断就可以了 ) { [self setupAutoWidthFlowItems:[temp copy] withPerRowItemsCo ...

  6. 一条命令使win7可以直接运行.net3.5程序

    dism /online /get-features 获取 功能名称 dism /online /enable-feature /featurename:NetFx3  启用win7自带的.net f ...

  7. OC基础--ARC的基本使用

    一.ARC的判断准则:只要没有强指针指向对象,就会释放对象 二.ARC特点: 1>不允许使用release.retain.retainCount 2>允许重写dealloc,但是不允许调用 ...

  8. IntellJ IDEA 所有快捷键

    登录下面网站. http://www.jetbrains.com/idea/documentation/ 下载Keymap for Windows/Linux 后面的PDF文档.

  9. 小菜鸟学 Spring-Dependency injection(二)

    注入方式一:set注入 <bean id="exampleBean" class="examples.ExampleBean"> <!-- s ...

  10. struts2面试题汇总

    一.工作原理 一个请求在Struts2框架中的处理大概分为以下几个步骤 1 客户端初始化一个指向Servlet容器(例如Tomcat)的请求 2 这个请求经过一系列的过滤器(Filter)(这些过滤器 ...