uva 11729

A B C D

B - Commando War

Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status Practice UVA 11729

Appoint description: 
System Crawler  (2014-11-25)

Description


G


Commando War

Input: Standard Input

Output: Standard Output

“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 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)seconds are needed to brief the soldier while completing his job needs 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                                               Output for Sample Input


3

2 5

3 2

2 1

3

3 3

4 4

5 5

0


Case 1:8

Case 2: 15

 


Problem Setter: Mohammad Mahmudur Rahman, Special Thanks: Manzurur Rahman Khan

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
int n,ans;
struct node
{
      int x,y;
}e[1010];
bool cmp(node a,node b)
{
      return a.y>b.y;
}
int main()
{
      int cas=1;
      while(scanf("%d",&n),n)
      {
            ans=0;
            int s=0;
            for(int i=1;i<=n;i++)
                  scanf("%d%d",&e[i].x,&e[i].y);
            sort(e+1,e+1+n,cmp);
            for(int i=1;i<=n;i++)
            {
                 s+=e[i].x;
                 ans=max(ans,s+e[i].y);
            }
            printf("Case %d: %d\n",cas,ans);
            cas++;
      }
      return 0;
}

  

时间: 2024-10-26 09:31:17

uva 11729的相关文章

贪心 UVA 11729 Commando War

题目传送门 1 /* 2 贪心:按照执行时间长的优先来排序 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <iostream> 7 #include <cstring> 8 #include <string> 9 #include <cmath> 10 using namespace std; 11 12 const int MAXN = 1e3 + 10; 13

UVA 11729 Commando War 突击战 【贪心】

题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28436 贪心 按照工作执行时间的从长到短进行排序,之后计算总的执行时间(反证见刘汝佳P4) 计算方法: 先按照交代任务的时间依次累加,就是本次任务开始执行时的时间,这个时间加上任务完成的时间就是这次任务执行完毕后需要的总时间 这个总时间如果没有之前的总时间长的话表示这次任务的执行时间是包括在上次任务的执行时间之间的 超出的话就要更新总的任务执行时间 最后输出总的

突击战 (UVA 11729)

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28436 思路:任务从开始时就不停执行,与其他任务毫无关联,当然是执行时间越长的任务越早执行好了 #include <iostream> #include <algorithm> #include <cstdio> #define RPE(i,n) for(int i=0;i<n;i++) using namespace std; c

UVA 11729 Commando War

Commando WarInput: Standard InputOutput: Standard Output “Waiting for orders we held in the wood, word from the front never cameBy evening the sound of the gunfire was miles awayAh softly we moved through the shadows, slip away through the treesCross

UVA 11729 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 hand

UVa 11729 Commando War 【贪心】

题意:有n个部下,交待每个部下完成他相应的任务需要bi的时间,然后完成这项任务需要ji的时间, 选择交待任务的顺序,使得总的花费的时间最少 因为不管怎么样,交待所需要的n*bi的时间都是要花费的, 然后就让完成任务需要的时间长的人先做,就将j按降序排,更新每完成一个人的任务所花费的时间 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #inclu

UVA 11729 Commando War (贪心)

题目链接:https://vjudge.net/problem/UVA-11729 一道比较显然的贪心. 我们可以发现如果我们让$a_j$最大的尽可能地往前来交待,那么时间重合地会更多. 一个很明显的贪心策略:按照$j$从大到小排序,记录每一次的$s$(交代的时间)和$s+a_j$(结束的时间),用结束的时间来更新$ans$. 证明其正确性:(蓝书 P4) 可以使用最常见的交换论证法: 假设我们交换相邻的两个任务$X$和$Y$,不难发现交换前后只会对$X$和$Y$有关. 情况一:交换之前,$X$

大白书

UVA 11292 (简单贪心) 题意: n条恶龙,m个勇士,用勇士来杀恶龙.一个勇士只能杀一个恶龙.而且勇士只能杀直径不超过自己能力值的恶龙.每个勇士需要支付能力值一样的金币.问杀掉所有恶龙需要的最少金币. 思路: 贪心,均从小到大排序.为每一条龙找一个恰好能杀他的骑士.简单贪心. UVA 11729 (经典贪心问题) 题意: n个任务,需要交代B分钟,执行J分钟,让你合理选择交代任务的次序,求得n个任务完成的最小总时长. 思路: 经典贪心,通过比较俩俩的关系,得到整个序列的贪心排序方法.这个

cumt周练题解

cumt2017春季--周练(一) A.CodeForces - 785A 1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n; 6 cin >> n; 7 map<string, int>ma; 8 ma["Tetrahedron"] = 4; 9 ma["Cube"] = 6; 10 ma["Octahedron&quo