//SOL private static void Solve(int[] arr, InOut.Ergebnis erg) { string res = ""; IQueue <int> q = new PrioArrayQueue <int>(arr[0], (z, z2) => z.CompareTo(z2)); for (int i = 1; i < arr.Length; i++) { if (arr[i] == -1) { q.Dequeue(); } else { q.Enqueue(arr[i]); } } while (!q.IsEmpty()) { res += q.Dequeue() + " "; } erg.Setze(res.Trim(' ')); }
public static void Scheduler(char[] tasks, int delay, InOut.Ergebnis erg) { Dictionary <char, int> lastPos = new Dictionary <char, int>(); LinkedList <char> list = new LinkedList <char>(); PrioArrayQueue <Payload> q = new PrioArrayQueue <Payload>((p, p2) => p.wait.CompareTo(p2.wait)); q.AddStringConverter(p => p.c + ", "); int time = 0; int count = 0; Wrapper <char> task = new Wrapper <char>(); while (!q.IsEmpty() || count < tasks.Length) { task.IsNull = true; if (count < tasks.Length) { task.Val = tasks[count++]; if (lastPos.ContainsKey(task.Val)) // Check if already encounterd { if (time - lastPos[task.Val] <= delay) // Check if delay time has run out; If then immideatly add to List instead of queuing // Still in Delay { q.Enqueue(new Payload(task.Val, time + 1 + (delay - time + lastPos[task.Val]))); // Put in Prio qeue (calculate minimum next time step) lastPos[task.Val] += delay + 1; // simulate listing by adding delay time continue; } } else { lastPos.Add(task.Val, 0); } } if (task.IsNull) { task.Val = q.Peek().wait <= time?q.Dequeue().c : '/'; } list.AddLast(task.Val); if (task.Val != '/') { lastPos[task.Val] = Math.Max(time, lastPos[task.Val]); } time++; } erg.Setze(list.ToArray()); }
public static void FindClosestPoints(Helfer.Point[] points, int k, InOut.Ergebnis erg) { Func <Helfer.Point, int> GetDistance = p => p.X * p.X + p.Y * p.Y; // Distance to origin squared PrioArrayQueue <Helfer.Point> prioQ = new PrioArrayQueue <Helfer.Point>(k, (p, p2) => GetDistance(p).CompareTo(GetDistance(p2)), true); foreach (Helfer.Point p in points) { prioQ.Enqueue(p); } Helfer.Point[] ergArr = new Helfer.Point[k]; for (int i = 0; i < ergArr.Length; i++) { ergArr[i] = prioQ.Dequeue(); } erg.Setze(ergArr); }