Commando War
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的更多相关文章
- uva----11729 Commando war (突击战争)
G Commando War Input: Standard Input Output: Standard Output “Waiting for orders we held in the wood ...
- 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 ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- 贪心 UVA 11729 Commando War
题目传送门 /* 贪心:按照执行时间长的优先来排序 */ #include <cstdio> #include <algorithm> #include <iostrea ...
- cogs 1446. [Commando War,Uva 11729]突击战
1446. [Commando War,Uva 11729]突击战 ★ 输入文件:commando.in 输出文件:commando.out 简单对比时间限制:1 s 内存限制:64 ...
- [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 ...
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
- Commando War (贪心)
Waiting for orders we held in the wood, word from the front never came By evening the sound of the g ...
- Uva11729 Commando War
相邻两个士兵交换顺序,不会对其他的有所影响,贪心考虑两两之间交换策略即可. sort大法好.印象中这类排序题里有一种会卡sort,只能冒泡排序,然而到现在还没有遇到 /**/ #include< ...
随机推荐
- css兼容性的问题
https://www.douban.com/note/314793848/ 随意的一个博客ie6的兼容 这个博客比较好 http://blog.csdn.net/chuyuqing/article/ ...
- 编写高质量代码改善C#程序的157个建议[IEnumerable<T>和IQueryable<T>、LINQ避免迭代、LINQ替代迭代]
前言 本文已更新至http://www.cnblogs.com/aehyok/p/3624579.html .本文主要学习记录以下内容: 建议29.区别LINQ查询中的IEnumerable<T ...
- 【Javascript】—— 1 方法function的高级特性
本篇仅仅对于function作简单的讲解,在javascript中function不仅仅是方法,它其实是一个变量,因此拥有自己的属性,并且可以当做参数传递给其他的方法. 那么传统的方法,按照java的 ...
- int和integer的比较
程序代码: Integer i01 = 59; int i02 = 59; Integer i03 =Integer.valueOf(59); Integer i04 = new Integer(59 ...
- 【HDU 5387】Clock
题 Description Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hour. ...
- Android intent传递list或对象
方法一: 如果单纯的传递List<String> 或者List<Integer>的话 就可以直接使用 Java代码 intent.putStringArrayListExtra ...
- LinkedHashMap实现LRU算法
LinkedHashMap特别有意思,它不仅仅是在HashMap上增加Entry的双向链接,它更能借助此特性实现保证Iterator迭代按照插入顺序(以insert模式创建LinkedHashMap) ...
- BZOJ-1228 E&D 博弈SG+找啊找啊找规律
讨厌博弈,找规律找半天还是错的.... 1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MB Submit: 666 Solv ...
- BZOJ-1207 打鼹鼠 DP(LIS)
1207: [HNOI2004]打鼹鼠 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2276 Solved: 1116 [Submit][Statu ...
- 【poj1015】 Jury Compromise
http://poj.org/problem?id=1015 (题目链接) 题意 随机挑选n个人作为陪审团的候选人,然后再从这n个人中选m 人组成陪审团.选m人的办法是:控方和辩方会根据对候选人的喜欢 ...