介绍
在策略游戏《星际争霸2》中,有三个“种族”可供选择:人族,虫族和神族。在这一挑战中,我们将重点关注神族和标志性短语“您必须建造更多的塔!” 当您用尽兵力建立军队时,就会显示此信息。因此,要帮助Starcraft社区,您必须编写一个程序或函数来告诉玩家他们到底需要多少个挂架。
挑战
您将得到一个字符串输入,该字符串由一个整数N
和以空格分隔的单位列表组成。N
将始终为零或正数,并且单位列表将始终具有一个或多个有效单位。N
代表玩家当前拥有的塔架数量。您的工作是计算玩家所拥有的塔架数量是否足以构建单位。你的程序或函数必须输出/返回truthy值,如果有足够的供应,或者如果没有足够的供应,你必须输出You must construct ZZZ additional pylons
哪里ZZZ
是建设单位需要挂架的量。请注意,pylon(s)
在需要时必须为复数,而在不需要时为(...1 additional pylon!
,...2 additional pylons!
),则不能为复数。
神族单位和供应成本
这是所有单位及其相应供应成本的列表。挂架额外提供8个电源。
Unit Supply Cost
Probe 1
Zealot 2
Sentry 2
Stalker 2
HighTemplar 2
DarkTemplar 2
Immortal 4
Colossus 6
Archon 4
Observer 1
WarpPrism 2
Phoenix 2
MothershipCore 2
VoidRay 4
Oracle 3
Tempest 4
Carrier 6
Mothership 8
没有奖金的例子
Input:
2 Probe Probe Probe Probe Stalker Zealot Carrier Probe Zealot
Output:
You must construct 1 additional pylon!
Why?
Adding up the supply costs for all of the units gives 17. The current 2 pylons provide 16 supply, so one more is needed to provide enough for 17.
Input:
5 Mothership Carrier Probe Tempest HighTemplar
Output:
true
Why?
Adding up the units gets 21. The current 5 pylons provide 40 supply, which is plenty enough.
Input:
0 Mothership Colossus Zealot
Output:
You must construct 2 additional pylons!
Why?
Adding the units gets 16. There is no pylons so 2 need to be built to provide enough supply.
奖金
- 任何有经验的Starcraft 2玩家都会知道,在将其转变为母舰之前,您需要一个母舰核心。此外,您一次只能拥有一个母权(无论是实际母权还是母权核心)。如果这些条件都不成立,则输出任何虚假值。如果您的程序可以一次查看只有一个母舰处于活动状态,并且在实际母舰之前建立了一个母舰核心,请从您的字节数中减去20%。
- 您可能知道的很少,但是联系(神族命令中心)实际上也提供了补给!如果您的程序每次在单位列表中遇到联系时都可以在最大供给量上增加11,请减少字节数10%。请注意,Nexus在构建顺序中的位置并不重要,因此
0 Probe Nexus
仍会返回true
。
奖金示例
Input (Bonus 1):
3 Mothership Zealot
Output:
false
Why?
According to the first bonus, a mothership core has to be built before a mothership.
Input (Bonus 1):
3 MothershipCore Mothership MothershipCore
Output:
false
Why?
According to the first bonus, only one mothership can be built and here there is two (MothershipCore -> Mothership and a second MothershipCore).
Input (Bonus 2):
0 Probe Nexus Probe
Output:
true
Why?
According to the second bonus, nexuses add 11 to the maximum supply, allowing both probes to be built.
Input (Both Bonuses):
0 Nexus MothershipCore Mothership Carrier
Output:
You must construct 1 additional pylon.
Why?
There are no pylons, but the nexus provides 11 supply. The motherships take up 2 and 8, respectively and the carrier takes up 6. You need one more pylon to have enough to provide for all 16 supply.
TL; DR
输入由整数和空格分隔的单元名称组成的字符串(来自上表)。如果可以使用N
挂架提供的电源(输入中的整数)构建所有单元,则输出真实值。You must construct ZZZ additional pylon(s)
如果需要更多的定向塔,则输出,所需定向塔的数量在哪里ZZZ
。如有必要,确保将塔架复数。
这是代码高尔夫球,因此以字节为单位的最短代码(或您语言的计数方法)获胜!
排行榜
这是一个堆栈片段,用于按语言生成常规排行榜和获胜者概述。
为确保您的答案显示出来,请使用以下Markdown模板以标题开头。
# Language Name, N bytes
N
您提交的文件大小在哪里。如果您提高了分数,则可以将旧分数保留在标题中,方法是将它们打掉。例如:
# Ruby, <s>104</s> <s>101</s> 96 bytes
如果要在标头中包含多个数字(例如,因为您的分数是两个文件的总和,或者您想单独列出解释器标志罚分),请确保实际分数是标头中的最后一个数字:
# Perl, 43 + 2 (-p flag) = 45 bytes
您还可以将语言名称设置为链接,然后该链接将显示在页首横幅代码段中:
# [><>](http://esolangs.org/wiki/Fish), 121 bytes
var QUESTION_ID=69011,OVERRIDE_USER=36670;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?([\d\.]+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
N unit1 unit2 unit3...
。
true
还是可以接受真实值?