-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
44 lines (43 loc) · 1.34 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
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
namespace LineReflection
{
class Program
{
static void Main(string[] args)
{
int[][] points = new[]
{
new[] {0, 0},
};
Console.WriteLine(IsReflected(points));
}
static bool IsReflected(int[][] points)
{
var records = new Dictionary<int, List<int>>();
foreach (var point in points)
{
if(!records.ContainsKey(point[1]))
records[point[1]] = new List<int>();
if (!records[point[1]].Contains(point[0]))
records[point[1]].Add(point[0]);
}
var reflection = new HashSet<double>();
foreach (var record in records)
{
record.Value.Sort();
int li = 0, hi = record.Value.Count - 1;
double middlePoint = ((double)record.Value[hi] + record.Value[li]) / 2;
while (li <= hi)
{
if (((double)record.Value[hi] + record.Value[li]) / 2 != middlePoint)
return false;
li++;
hi--;
}
reflection.Add(middlePoint);
}
return reflection.Count == 1;
}
}
}