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 haveNsoldiers 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 soldierbegins 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 integerN (1<=N<=1000), denoting the number of soldiers. Each of the following N lines describe a soldier with two integersB (1<=B<=10000)&J
(1<=J<=10000).Bseconds are needed to brief the soldier while completing his job needsJseconds. The end of input will be denoted by a case withN =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 InputOutput for Sample Input
3
2 5
3 2
2 1
3
3 3
4 4
5 5
0
|
Case 1:8
Case 2: 15
|
【题目翻译】:
【思路】:
贪心算法:处理时间长的先交代。按照J从大到小的顺序给任务排序,依次交代。
【代码】:
-
-
-
-
-
-
-
-
-
-
#include<stdio.h>
-
#include<stdlib.h>
-
-
typedefstructTime{
-
-
intB;
-
-
intJ;
-
}Time;
-
-
-
intcmp(constvoid*a,constvoid*b){
-
structTime*c=(Time*)a;
-
structTime*d=(Time*)b;
-
returnd->J-c->J;
-
}
-
-
TimeT[1001];
-
-
intmain()
-
{
-
inti,N,Case=1;
-
-
while(scanf("%d",&N)!=EOF&&N!=0){
-
-
for(i=0;i<N;i++){
-
scanf("%d%d",&T[i].B,&T[i].J);
-
}
-
-
qsort(T,N,sizeof(T[0]),cmp);
-
intstartTime=0;
-
intendTime=0;
-
for(i=0;i<N;i++){
-
-
startTime+=T[i].B;
-
-
if(endTime<T[i].J+startTime){
-
endTime=T[i].J+startTime;
-
}
-
}
-
printf("Case%d:%d\n",Case,endTime);
-
Case++;
-
}
-
return0;
-
}
-
-
分享到:
相关推荐
代码可以解决 Commando War ,代码很简练
资源来自pypi官网。 资源全名:django-commando-0.1.1.tar.gz
its-not-commando是一个简单的discord.js命令框架,功能轻巧且易于使用。在设计方面,它与非常相似。 就个人而言,我在所有discord.js项目中都使用了此框架。 特征 易于使用的命令系统使用现代javascript async / ...
Commando Discord机器人基于discord.js-commando构建。 贡献 叉子! 创建功能分支: git checkout -b my-new-feature 提交更改: git commit -am 'Add some feature' 推送到分支: git push origin my-new-...
bot.js-commando 用于创建自己的Commando Discord机器人的模板。 它仍处于完全开发中,许多事情仍然可以更改。支持如果您需要使用此模板的帮助,当它越来越接近完成时(暂时不行,但您仍然可以加入),请加入我们的...
TwitchBot 使用Discord.js-Commando和Twitch API构建的Discord Twitch集成机器人信息TwitchBot是具有无数命令和功能的流通知机器人! 很快会有抽搐聊天和您的流的自定义抽搐小部件/面板出现! TwitchBot内置在...
TurtyBot-Commando 我服务器的不和谐机器人
kajzerkaBot:我用discord.js-commando编写的个人discord机器人
Commando war 突击队战争是一款惊心动魄的动作射击游戏! 支持Unity版本5.3.5及以上 突击队战争是一款惊心动魄的动作射击游戏! 一名罪犯试图逃离警察的追捕。当他与愤怒的警察战斗时帮助他! Commando War 有 2 个...
VESHIT-Bot_commando VESIT-Bot但基于Commando.js和Firebase
MFGJ-2021-Jan
找平系统可能即将添加! 通过使用MongoDB数据库。 可以将BOT邀请到您自己的服务器。 该机器人的自托管问题不会得到该机器人开发人员的帮助。 代码错误,错误可能会由开发人员提供帮助,但没有优先级。...
彩色突击队 Unity制作的3D AR第一人称射击游戏
Pokemon_Bot 重写版本可以在找到
欢迎使用Discord Commando AI存储库! 我们将介绍该机器人的构建方式和使用方法。 店里有什么? 内置突击队该机器人安装了Commando软件包,这是用于构建命令的附加软件包。您可以在获取软件包。 在我们当中自2020年...
不和谐音乐机器人 不在主动开发中,可能包含问题和错误 Discord voip应用程序的音乐bot,仅包含音乐播放代码,没有其他不必要的开销代码。 自由分叉和/或贡献。 为稳定版本克隆master分支。 非常欢迎任何错误报告或...
commando-vm:完整的Mandiant进攻VM(Commando VM),这是一个完全可定制的基于Windows的渗透测试虚拟机发行版。 commandovm@fireeye.com
Commando 灵感来自于 Python 的 optparse 模块 以及 JewelCli Java 库,是一个用来定义以及解析 命令行参数的Python工具包。 标签:Commando
突击队FaunaDBProvider 关于 是的官方框架。 为了使Faunadb与bot的连接更容易一些,我从框架中将sqliteProvider“重新制作”为使用FaunaDB。 ...const FaunaProvider = require ( 'commando-provid
commando:Commando:LinuxOSX命令行简单指南