I - Commando War

news/2025/3/29 19:34:59/
先读懂题意,先排序,在相加,贪心算法重在思路。



I -
Commando War
Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit Status

Description

Download as PDF


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 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                                               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<stdio.h>
int b[10001],c[10001],t[10001]={0};
int main()
{int i,j,w,m;int a,q=0;while(scanf("%d",&a)!=EOF){if(a==0)break;q++;for(i=0;i<a;i++)scanf("%d%d",&b[i],&c[i]);for(i=0;i<a;i++){for(j=0;j<i;j++){if(c[i]>c[j]){w=c[i];c[i]=c[j];c[j]=w;w=b[i];b[i]=b[j];b[j]=w;}}}t[0]=b[0];for(i=0;i<a;i++){t[i]=t[i-1]+b[i];}for(i=0;i<a;i++){t[i]=t[i]+c[i];}m=t[0];for(i=0;i<a;i++){if(m<t[i])m=t[i];}printf("Case %d: %d\n",q,m);}}



http://www.ppmy.cn/news/906712.html

相关文章

commands(commands软件)

QQ任逍遥为什么老“badsequenceofcommands”? bad sequence of commands的意思是&#xff1a;命令的次序错误。 WINDOWS动态链接库中文件丢失会造成软件运行参数错误&#xff0c;就会造成你的这个现象。 所以很可能是你的软件运行时参数有问题&#xff0c;电脑提示bad seque…

Command命令模式

简介&#xff1a; 简单来说&#xff0c;就像我们的复制、删除、插入等等都是命令&#xff0c;我们将命令封装为一个对象&#xff0c;并且支持撤销&#xff0c;将一系列命令串成一条链或者与链表结合使用&#xff0c;可以实现一系列的do和undo 模式类图&#xff1a; command: …

more command

文章目录 1.命令简介2.命令格式3.选项说明4.交互式命令5.环境变量6.常用示例参考文献 1.命令简介 more 是常用的文本文件阅读工具。 more 类似于 cat&#xff0c;不过以一页一页的形式显示&#xff0c;便于逐页阅读。一般文件过大时使用 more 浏览&#xff0c;文件较小时使用…

commandos 系列

盟军敢死队1秘籍2008-03-23 12:42 无敌密技&#xff1a;   游戏进行中打GONZO1982或1982GONZO,然后即可使用如下密技:  SHIFTV--追踪  SHIFTX--瞬间移动  CTRLI--无敌  CTRLSHIFTN--完成任务  CtrlShiftX--敌人全爆  选关密码&#xff1a;  MISSION2: 4JJXB …

K11375 突击战[Commando War,UVa11729]

题目描述 你有N个部下&#xff0c;每个部下需要独立完成一项任务。第i个部下需要你花费Bi分钟交代任务&#xff0c;然后他会立刻独立、无间断地执行Ji分钟后完成任务。你需要选择交代任务的顺序&#xff0c;使得所有任务尽早执行完毕&#xff08;即最后一个执行完的任务应尽早…

du command

文章目录 1.命令简介2.命令格式3.选项说明4.常用示例5.注意事项6.小结参考文献 1.命令简介 du&#xff08;disk usage&#xff09;用于查看指定的目录或文件所占用的磁盘空间。 2.命令格式 du [OPTIONS] [FILES] du [OPTIONS] --files0-fromF3.选项说明 -a, --all递归显示目…

command-codes

Hierarchy Commands TPM2_CreatePrimary 此命令用于在主种子之一下创建主对象或在 TPM_RH_NULL 下创建临时对象。 该命令使用 TPM2B_PUBLIC 作为要创建的对象的模板。 不应检查唯一字段的大小是否与其他对象参数一致。 该命令将创建并加载一个主对象。 不返回敏感区域。 注…

Command(命令模式)行为型

这命令模式 一、概述二、结构三、实例四、适用场景五、优缺点 一、概述 描述&#xff1a;看电视时&#xff0c;只需要轻轻一按遥控器就能完成频道的切换&#xff0c;这就是命令模式&#xff0c;将换台请求和换台处理完全解耦了。电视机遥控器&#xff08;命令发送者&#xff0…