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< ...
随机推荐
- php 利用socket发送GET,POST请求
作为php程序员一定会接触http协议,也只有深入了解http协议,编程水平才会更进一步.最近我一直在学习php的关于http的编程,许多东西恍然大悟,受益匪浅.希望分享给大家.本文需要有一定http ...
- Object C学习笔记20-结构体
在学习Object C中的过程中,关于struct的资料貌似非常少,查阅了C方面的资料总结了一些学习心得! 一. 定义结构 结构体是一种数据类型的组合和数据抽象.结构体的定义语法如下: struct ...
- [BZOJ 1297][SCOI 2009]迷路(矩阵快速幂)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1297 分析:如果每条边的边权都是1,那么就相当于对邻接矩阵自乘T次(因为写一下递推式子 ...
- javascript继承(五)—prototype最优两种继承(空函数和循环拷贝)
一.利用空函数实现继承 参考了文章javascript继承—prototype属性介绍(2) 中叶小钗的评论,对这篇文章中的方案二利用一个空函数进行修改,可以解决创建子类对象时,父类实例化的过程中特权 ...
- 第四十二课:基于CSS的动画引擎
由于低版本浏览器不支持css3 animation,因此我们需要根据浏览器来选择不同的动画引擎.如果浏览器支持css3 animation,那么就使用此动画引擎,如果不支持,就使用javascript ...
- jQuery使用之(一)标记元素属性
jQuery使用主要介绍jQuery如何控制页面,包含元素的属性.css样式风格.DOM模型.表单元素和事件处理等. 标记元素的属性 html中每一个标记都具有一些属性,他们这个标记在页面中呈现各种状 ...
- dell r710 服务器配置RAID5(3块硬盘做RAID5,另外再弄一块做数据冗余盘)
本文完全转载于:http://www.jb51.net/article/53814.htm,只为做笔记使用 ①4块硬盘做成RAID5 ②3块硬盘做RAID5,一块硬盘做热备盘 这两种配置之间的区别.大 ...
- WordPress HOOK机制原理及代码分析
WordPress强大的插件机制让我们可以自由扩展功能.网上对插件的使用以及开发方法都有大量资料可以查询. 今天我们就分析一下四个主要函数的代码,包括: add_action.do_action.ad ...
- 【BZOJ-2843&1180】极地旅行社&OTOCI Link-Cut-Tree
2843: 极地旅行社 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 323 Solved: 218[Submit][Status][Discuss ...
- BZOJ4034 T2
Description 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操作 2 :把某个节点 x 为根的子树中所 ...