-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
34 lines (32 loc) · 1 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
34
using System;
namespace SquirrelSimulation
{
class Program
{
static void Main(string[] args)
{
int height = 5, width = 5;
int[] tree = {3, 2}, squirrel = {0, 1};
int[][] nuts = new[]
{
new[] {0, 2},
new[] {0, 0},
new[] {2, 2},
};
Console.WriteLine(MinDistance(height, width, tree, squirrel, nuts));
}
public static int MinDistance(int height, int width, int[] tree, int[] squirrel, int[][] nuts)
{
int res = 0, dis = int.MinValue;
foreach (var nut in nuts)
{
var temp1 = Distance(nut, squirrel);
var temp2 = Distance(nut, tree);
res += 2 * temp2;
dis = Math.Max(dis, temp2 - temp1);
}
return res - dis;
}
public static int Distance(int[] p1, int[] p2) => Math.Abs(p1[0] - p2[0]) + Math.Abs(p1[1] - p2[1]);
}
}