-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
33 lines (32 loc) · 1.11 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//只要你能比鬼先到target就可以逃脱。
//创建StepsToTarget方法计算到target所需的步数。
//在主方法中计算你到达target所需的步数和所有鬼中,到达target最少的步数。
//返回你的步数小于贵的步数。
using System;
namespace EscapeTheGhosts
{
class Program
{
static void Main(string[] args)
{
int[] start = { 2, 3 };
int[] target = { 1, 1 };
Console.WriteLine(StepsToTarget(start, target));
}
static bool EscapeGhosts(int[][] ghosts, int[] target)
{
int yourSteps = StepsToTarget(new int[2] { 0, 0 }, target);
int ghostMinSteps = int.MaxValue;
foreach (var g in ghosts)
{
int ghostSteps = StepsToTarget(g, target);
ghostMinSteps = Math.Min(ghostMinSteps, ghostSteps);
}
return yourSteps < ghostMinSteps;
}
static int StepsToTarget(int[] start, int[] target)
{
return Math.Abs(target[0] - start[0]) + Math.Abs(target[1] - start[1]);
}
}
}