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. NFine框架的T4模板

    1.前言 前段时间在网上看到一个开源框架很好的.开源:ASP.NET MVC+EF6+Bootstrap开发框架,写代码就是比较比较麻烦,分层比较多,对于我这种偷懒的人就想到了写一个T4模板.不了解框 ...

  2. 分页pagination实现及其应用

    1.分页jquery.page.js //分页插件 /** 2014-08-05 ch **/ (function ($) { var ms = { init: function (obj, args ...

  3. 【前端开发系列】—— CSS3属性选择器总结

    想想自己为什么要学CSS,作为一个开发过前端的人员来说,调试一个图片花了半天的时间,最后发现分隔符用错了,实在是一件很丢人的事情.因此,痛下决心来学习CSS,最近一周也会更新下相关的学习笔记. CSS ...

  4. 【BZOJ 1001】狼抓兔子 对偶图+SPFA

    这道题是求图的最小割,也就是用最大流.但因为边太多,最大流算法会T,因此不能用最大流算法. 因为这是个平面图,所以求平面图的最小割可以使用特殊的技巧就是求对偶图然后求对偶图的最短路.把每个面看成一个点 ...

  5. 在CentOS7上安装RabbitMQ

    安装过程参考官网: Installing on RPM-based Linux (RHEL, CentOS, Fedora, openSUSE) 首先需要安装erlang,参考:http://fedo ...

  6. .Net身份验证概述

    一直以来,所有的系统基本都会有用户的登陆验证过程,整个过程其实也不难理解,就是对于cookie的解析.微软的.Net平台围绕用户身份验证授权也有好几个版本了,从早期的Membership到Identi ...

  7. 【HDU 5399】Too Simple

    题 Description Rhason Cheung had a simple problem, and asked Teacher Mai for help. But Teacher Mai th ...

  8. JAVA开发之Eclipse常用的快捷键

    Eclipse是我们常用的java开发编辑器,它支持很多有用但又不太为人所知的快捷键组合.通过这些组合快捷键我们可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升.甚至有一次笔者去参加一个IT ...

  9. 【poj1962】 Corporative Network

    http://poj.org/problem?id=1962 (题目链接) 时隔多年又一次写带权并查集. 题意 n个节点,若干次询问,I x y表示从x连一条边到y,权值为|x-y|%1000:E x ...

  10. 移动H5页面,keyup事件不好使用处理解决

    1.mouse事件换成touch,pointer事件,keyup换成textInput事件