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< ...
随机推荐
- 20145215《Java程序设计》第4周学习总结
20145215<Java程序设计>第四周学习总结 教材学习内容总结 继承与多态 继承 继承作为面向对象的第二大特征,基本上就是避免多个类间重复定义共同行为.即当多个类中存在相同属性和行为 ...
- Linux下高频命令分类辑录(基本使用篇)
本文目的:总结linux下常用命令的基本使用方法 文件权限: 文档权限设置命令:chmod 数字模式: 文档权限由-rwxrwxrwx十个字符组成,其中第一个代表文档类型,后面九个字符按照顺序分为三组 ...
- 嵌入式linux驱动开发之点亮led(驱动编程思想之初体验)
这节我们就开始开始进行实战啦!这里顺便说一下啊,出来做开发的基础很重要啊,基础不好,迟早是要恶补的.个人深刻觉得像这种嵌入式的开发对C语言和微机接口与原理是非常依赖的,必须要有深厚的基础才能hold的 ...
- Highcharts candlestick(K线图)案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 24.C#LINQ TO XML(十二章12.3)
自己也写了那么多,但还有很多不懂,有点浮躁吧,但饭还是要吃啊,说说LINQ TO XML吧. LINQ TO XML位于System.Xml.Linq程序集,并且大多数类型位于System.Xml.L ...
- Mac上git的安装配置与使用简述
Mac下git搭建及使用 之前就只是经常在GitHubs上下载代码,也没注意怎么上传项目.一开始对git都没什么了解花了几个小时去小补了下知识.如果有需要可以转去这里学习:[GIT使用简易指南] (h ...
- 坑爹的BFC;块格式上下文
Formatting context(FC) Formatting context 是 W3C CSS2.1 规范中的一个概念.它是页面中的一块渲染区域,并且有一套渲染规则,它决定了其子元素将如何定位 ...
- Quartz 定时任务管理
前言 将项目中的所有定时任务都统一管理吧,使用 quartz 定时任务 设计思路 使用 quartz 的相关jar 包,懒得去升级了,我使用的是 quart 1.6 写一个定时任务管理类 用一张数据库 ...
- Freemarker-数字默认格式化问题
freemarker在解析数据格式的时候,默认将数字按3位来分割 例如1000被格式化为1,000 这样做看似美观,但在实际操作时候会带来问题.例如我一个页面有一个元素,该元素的值由后台绑定且超过10 ...
- FooTable高级的响应式表格jQuery插件
FooTable是一个高级jQuery插件,允许开发者在触屏智能手机及平板电脑等小型设备上制作数据非常惊人的HTML表格.它可以将HTML表转换成可扩展的响应式表格,且通过单击某一行即可将该行数据隐藏 ...