commit 51169e6a8a82ae11aa58bd1daba109b94cc88971
parent 90546fc1d5fcd810c4fa0564d031940f024a17ae
Author: zerous Naveen Narayanan <zerous@nocebo.space>
Date: Fri, 1 Mar 2019 01:01:18 +0100
Codility - Rubidium 2019 solution
Diffstat:
rubidium.c | | | 99 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 99 insertions(+), 0 deletions(-)
diff --git a/rubidium.c b/rubidium.c
@@ -0,0 +1,99 @@
+#include <stdio.h>
+#include <math.h>
+
+int func1 (int *, int *, int);
+
+int
+main(int argc, char **argv)
+{
+ int d;
+
+ int a[4], b[4];
+
+ a[0] = 0;
+ a[1] = 0;
+ a[2] = 10;
+ a[3] = 10;
+
+ b[0] = 0;
+ b[1] = 10;
+ b[2] = 0;
+ b[3] = 10;
+
+ d = func1(a, b, 4);
+
+ printf("%d\n", d);
+
+ return 0;
+}
+
+int
+func1(int *x, int *y, int N)
+{
+ int t;
+ int res;
+
+ res = sqrt(pow((x[0] - x[1]), 2) + pow((y[0] - y[1]),2));
+
+ for (int i = 1; i < N; i++)
+ for (int j = 1; j < N; j++)
+ if (i != j) {
+ t = sqrt(pow((x[i] - x[j]),2) +
+ pow((y[i] - y[j]),2));
+
+ if (t < res)
+ res = t;
+ }
+ return res/2;
+}
+
+/* int */
+/* func(int *x, int *y, int N) */
+/* { */
+/* int i; */
+
+/* point *points = (point *) malloc(100000 * sizeof(point)); */
+
+/* for (i = 0; i < N; i++) { */
+/* points[i].x = x[i]; */
+/* points[i].y = y[i]; */
+/* } */
+
+/* heapperm(points, N, N); */
+
+/* free(points); */
+
+/* return 1; */
+/* } */
+
+/* void */
+/* heapperm(point *p, int size, int N) */
+/* { */
+/* static int d; */
+
+/* if (size == 1) { */
+/* for (int i = 0; i < N; i++) { */
+/* /\* printf("point x: %d point y: %d\n", p[i].x, p[i].y); *\/ */
+
+/* } */
+/* } */
+
+/* for (int i = 0; i < size; i++) { */
+/* heapperm(p, size - 1, N); */
+
+/* if (size % 2 == 1) */
+/* swap(p, 0, size - 1); */
+/* else */
+/* swap(p, i, size - 1); */
+/* } */
+/* } */
+
+/* void */
+/* swap(point *p, int a, int b) */
+/* { */
+/* point t; */
+
+/* t = p[a]; */
+/* p[a] = p[b]; */
+/* p[b] = t; */
+/* } */