问题陈述 - 死者之战 [英] Problem statement - battle of the dead

查看:109
本文介绍了问题陈述 - 死者之战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Problem Statement - Battle of the dead
Daenerys Targaryen is the mother of dragons, flying on her dragons towards the north to
destroy the army of dead(zombies). The zombies are oddly distributed in battlefield. She can
throw dragon fire to burn zombies in a circular spot of about 5 units in diameter but she can only
do this once before the dragon gets exhausted. She needs your help to decide where to throw
fire in order to burn maximum possible zombies.


Input
You will be given a collection of coordinates in battlefield where zombies are located.
Eg: [ { x: 10.5, y: 10.5 }, { x: 40.2, y: 30.6 },... ]


Output
Output the maximum number of zombies that can be burnt in one attack.

Method Signature
function burnThemAll( zombies ) => number

Limits
Time limit (s): 840.000
Memory limit (MB): 64

Constraints
● The size of battle field is constant (i.e. 50x50 units) for all the inputs.
● Both x and y values of the coordinates are in-between 0.0 unit and 50.0 unit.
● No two zombies are closer than 0.1 unit.
● Dragons may throw fire at any edge points of the battlefield also.
● If there is no zombie on battlefield, then return 0.
● Each zombie is considered a point. Each zombie is at a different position





我尝试过:





What I have tried:

function burnThemAll ( zombies ) {
	var feild_area = 50*50
	var burt_area = 0
	let z  = zombies.sort(function(a, b){return b['x'] - a['y']})
	// console.log(z[0].x-z[8].x)
	for (let i=0;i<z.length;i++){
		for (let j=0;j<i+1;j++){
			console.log(z[i]['x']-z[j]['x']);
		}
			// console.log(z[i]['x']-z[j]['x'])
			// console.log(z[i]['x']);

	}
}

推荐答案

我们不做你的功课:它设置为原因。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。

并且确定如何做到这一点是该任务的重要部分。



亲自尝试一下,你可能会发现它并不像你想象的那么难!

我会给你一个起点:你怎么样?手动做吗?假设你有一个棋子,棋子随机摆放着它。你的龙火击中了半径为2,因此它每次击中一个3 x 3板块,以她所针对的点为中心。

那你怎么决定哪个点如果你必须自己动手去瞄准?

当你解决这个问题时,翻译成计算机代码应该相当容易!



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
And working out how to do this is a significant part of that task.

Try it yourself, you may find it is not as difficult as you think!
I'll give you a starting point though: How would you do it manually? Assume you have a chessboard with pawns placed randomly about it. Your "dragon fire" hits a radius of two, so it hits a 3 x 3 "chunk" of the board each time, centered about the point she aims at.
So how would you decide which spot to aim for if you had to do it yourself?
When you work that out, it should be reasonably easy to translate into computer code!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


这篇关于问题陈述 - 死者之战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆