summaryrefslogtreecommitdiffstats
path: root/šola/p1/dn/DN02_63230317.java
diff options
context:
space:
mode:
Diffstat (limited to 'šola/p1/dn/DN02_63230317.java')
-rw-r--r--šola/p1/dn/DN02_63230317.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/šola/p1/dn/DN02_63230317.java b/šola/p1/dn/DN02_63230317.java
new file mode 100644
index 0000000..1eaa9de
--- /dev/null
+++ b/šola/p1/dn/DN02_63230317.java
@@ -0,0 +1,68 @@
+import java.util.*;
+public class DN01_63230317 {
+ public static int vrstica (int tipka) {
+ return (int) Math.sqrt(tipka);
+ }
+ public static int stolpec (int tipka) {
+ return tipka-vrstica(tipka)*vrstica(tipka)-vrstica(tipka);
+ }
+ public static int obroč (int tipka) {
+ return (int) Math.sqrt(tipka)/2;
+ }
+ public static int indeks (int tipka) {
+ return tipka-(obroč(tipka)*2)*(obroč(tipka)*2);
+ }
+ public static int velikost (int obr) {
+ return ((obr+1)*2)*((obr+1)*2) - (obr*2)*(obr*2);
+ }
+ public static int[] koordinate (int tipka) {
+ int koord[] = {
+ -obroč(tipka),
+ -obroč(tipka)
+ };
+ if (indeks(tipka) < velikost(obroč(tipka))/4) {
+ koord[0] += indeks(tipka);
+ return koord;
+ }
+ if (indeks(tipka) < velikost(obroč(tipka))/2) {
+ koord[0] += velikost(obroč(tipka))/4;
+ koord[1] += indeks(tipka);
+ return koord;
+ }
+ if (indeks(tipka) < 3*velikost(obroč(tipka))/4) {
+ koord[0] += velikost(obroč(tipka))/2-indeks(tipka);
+ koord[1] += velikost(obroč(tipka))/4;
+ return koord;
+ }
+ koord[1] += velikost(obroč(tipka))-indeks(tipka);
+ return koord;
+ }
+ public static int razdalja (int d, int oblika, int začetek, int konec) {
+ switch (oblika) {
+ case 1: // ravnovrstnica
+ return Math.abs(konec-začetek);
+ case 2: // kvadratnica
+ return Math.abs(konec%d-začetek%d)+Math.abs(konec/d-začetek/d);
+ case 3: // piramidnica
+ return Math.abs(vrstica(konec)-vrstica(začetek))+Math.abs(stolpec(konec)-stolpec(začetek));
+ case 4: // spiralnica
+ return Math.abs(koordinate(konec)[0]-koordinate(začetek)[0])+Math.abs(koordinate(konec)[1]-koordinate(začetek)[1]);
+ }
+ throw new Error("napačna tipkovnica");
+ }
+ public static void main (String[] args) {
+ Scanner sc = new Scanner(System.in);
+ int oblika = sc.nextInt();
+ int d = sc.nextInt();
+ int dolžina = sc.nextInt();
+ int pot = 0;
+ int stara = 0;
+ for (int i = 0; i < dolžina; i++) {
+ int tipka = sc.nextInt();
+ if (i > 0)
+ pot += razdalja(d, oblika, tipka, stara);
+ stara = tipka;
+ }
+ System.out.println(pot);
+ }
+}