// is26 // Ürmössy Dorottya, Budapest, Budapesti Fazekas M . Gyak. Ált. Isk. és Gimn // Microsoft Visual Studio Community 2015 Version 14.0.25431.01 // Visual C# 2015 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace is26 { class Program { static void readinput() { // read the 64 numbers into basetallon numbers = new int[64]; string line; string[] stringlist; // 0 1 2 3 4 5 6 // "0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 //line = "2 3 7 4 9 8 4 5 3 3 1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"; //line = "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1"; //line = "2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1"; //line = "2 4 8 8 2 4 8 8 2 4 8 8 2 4 8 8 2 4 8 8 2 4 8 8 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1"; //line = "5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8 5 5 5 8"; //line = "2 6 8 6 2 4 9 8 3 4 8 1 2 4 7 8 2 6 8 5 2 4 9 8 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1"; //line = "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1"; //line = "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1"; //line = "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1"; //line = "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1"; line = Console.ReadLine(); stringlist = line.Split(' '); for (int i = 0; i < 64; i++) numbers[i] = int.Parse(stringlist[i]); } static void writeoutput() { int steps = 0; int moves = bestmoves; int[] move = new int[8]; int i = 0; while (moves != 0) { move[i] = moves % 10; i++; steps += moves % 10; moves = moves / 10; } Console.WriteLine(steps); int huz = 8; List R = new List(); int counter = 0; // huzasok visszajátszása for (i = 0; i < 4; i++) { for (int j = 0; j < move[i]; j++) { for (int k = 0; k < huz; k++) { R.Add(numbers[counter]); counter++; } for (int k = 0; k < R.Count(); k++) { Console.Write("{0} ", R[k]); } Console.WriteLine(); } huz = huz / 2; } int dob = 8; counter = 0; List R21 = new List(); for (i = 0; i < sums[21][0].Count(); i++) R21.Add(sums[21][0][i]); // dobások visszajátszása for (i = 4; i < 8; i++) { for (int j = 0; j < move[i]; j++) { for (int k = 0; k < dob; k++) { int a = R[counter]; while (R21.Contains(a)) { R21.Remove(a); counter++; a = R[counter]; } R.RemoveAt(counter); //counter++; } for (int k = 0; k < R.Count(); k++) { Console.Write("{0} ", R[k]); } Console.WriteLine(); } dob = dob / 2; } // ellenörzésre /* for (i=0; i LA, List LB) { if (LA.Count != LB.Count) return false; for (int i = 0; i < LA.Count; i++) if (LA[i] != LB[i]) return false; return true; } static int calcsteps(int n, int d) { // ha az n.-ig kell minimum felhuzni és ebből d-t eldobunk, akkor az hány kör? // 8-as húzások és 8-as dobások darabszáma int h8f = n / 8; int d8f = d / 8; // 'utolsó' huzás / dobás rarabszáma int th = n - 8 * h8f; int td = d - 8 * d8f; int minstep = 256; for (int h8 = 0; h8 < 2; h8++) { for (int h4 = 0; h4 < 2; h4++) { for (int h2 = 0; h2 < 2; h2++) { for (int h1 = 0; h1 < 2; h1++) { for (int d8 = 0; d8 < 2; d8++) { for (int d4 = 0; d4 < 2; d4++) { for (int d2 = 0; d2 < 2; d2++) { for (int d1 = 0; d1 < 2; d1++) { int steps = h1 + h2 + h4 + h8 + d1 + d2 + d4 + d8; int ah = h1 * 1 + h2 * 2 + h4 * 4 + h8 * 8; int ad = d1 * 1 + d2 * 2 + d4 * 4 + d8 * 8; if (steps < minstep && ah >= th && ad >= td && th - td == ah - ad) { minstep = steps; lastmoves = 1 * (h8 + h8f) + 10 * h4 + 100 * h2 + 1000 * h1 + 10000 * (d8 + d8f) + 100000 * d4 + 1000000 * d2 + 10000000 * d1; } } } } } } } } } return h8f + d8f + minstep; } static bool search21() { bool result = false; int minstep = 256; sums = new List>>(); for (int i = 0; i < 22; i++) { List> ListList = new List>(); List List = new List(); ListList.Add(List); sums.Add(ListList); } for (int i = 0; i < 64; i++) { // minden magadott számra int a = numbers[i]; //Console.WriteLine(a); for (int j = 21; j >= 0; j--) { // ha a sums listában van már összeg, amihez ha az aktuális számot hozzáadjuk 22 alatt maradunk, if (j + a < 22 && sums[j][0].Count > 0) { // akkor a lista minden eleméhez füzzük hozzá az aktuális számot for (int k = 0; k < sums[j].Count; k++) { List List = new List(); // lemásoljuk a listát for (int m = 0; m < sums[j][k].Count(); m++) if (sums[j][k][m] != 0) List.Add(sums[j][k][m]); // és hozzáadjuk az aktuális számot List.Add(a); List.Sort(); // és a listát hozzáadjuk a sums megfelelő listájához, ha még nincs benne if (sums[a + j].Count == 1 && sums[a + j][0].Count == 0) { // üres lista volt benne sums[a + j].RemoveAt(0); sums[a + j].Add(List); if (a + j == 21) { minstep = calcsteps(i + 1, i + 1 - List.Count()); bestmoves = lastmoves; result = true; } } else { bool equalexists = false; for (int m = 0; m < sums[a + j].Count(); m++) if (equals(sums[a + j][m], List)) { equalexists = true; break; }; if (!equalexists) { if (a + j == 21) { int mstep = calcsteps(i + 1, i + 1 - List.Count()); if (mstep < minstep) { minstep = mstep; bestmoves = lastmoves; sums[a + j].RemoveAt(0); sums[a + j].Add(List); } } else { sums[a + j].Add(List); } } } } } } // a szám hozzáadása, ha még nincs a listán if (sums[a].Count == 1 && sums[a][0].Count == 0) { // üres lista volt a listán sums[a].RemoveAt(0); List List = new List(); List.Add(a); sums[a].Add(List); } else { List List = new List(); List.Add(a); bool equalexists = false; for (int m = 0; m < sums[a].Count(); m++) if (!sums[a][m].Equals(List)) { equalexists = true; break; }; if (!equalexists) sums[a].Add(List); } // a listák kiirása /* for (int j = 0; j < 22; j++) { // j- sor kiírása Console.Write("{0,2} : | ", j); for (int k=0; k>> sums; static int lastmoves = 0; static int bestmoves = 0; static void Main(string[] args) { readinput(); if (search21()) writeoutput(); else Console.WriteLine(0); //Console.ReadKey(); } } }