using
System;
using
System.Collections.Generic;
public
class
GFG {
public
class
pair {
public
float
first;
public
float
second;
public
pair(
float
f,
float
second) {
this
.first = f;
this
.second = second;
}
}
static
float
distance(
int
x1,
int
y1,
int
x2,
int
y2)
{
return
(
float
) Math.Sqrt(Math.Pow((x1 - x2), 2) +
Math.Pow((y1 - y2), 2));
}
static
List<List<
int
>> kClosest(
int
[,] points,
int
[] target,
int
K)
{
List<List<
int
>> pts =
new
List<List<
int
>>();
int
n = points.GetLength(0);
List<pair> d =
new
List<pair>();
for
(
int
i = 0; i < n; i++) {
d.Add(
new
pair(distance(points[i,0], points[i,1],
target[0], target[1]), i));
}
for
(
int
i = 0; i < K; i++) {
List<
int
> pt =
new
List<
int
>();
pt.Add(points[(
int
) d[i].second,0]);
pt.Add(points[(
int
) d[i].second,1]);
pts.Add(pt);
}
return
pts;
}
public
static
void
Main(String[] args) {
int
[,] points = { { 1, 3 }, { -2, 2 } };
int
[] target = { 0, 1 };
int
K = 1;
foreach
(List<
int
> pt
in
kClosest(points, target, K))
{
Console.Write(pt[0] +
" "
+ pt[1] +
"\n"
);
}
}
}