C
C#16mo ago
Spekulant

❔ just a quick help

using System;
using System.Collections.Generic;
using System.Linq;

class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(" ");
int[] limits = input[0].Split().Select(int.Parse).ToArray();
int[] initial = input[1].Split().Select(int.Parse).ToArray();


int m = limits.Max();
List<int> res = new List<int>();
List<int> resMoves = new List<int>();

for (int i = 0; i <= m; i++) {
int[] cur = initial.ToArray();
Queue<int[]> queue = new Queue<int[]>();
queue.Enqueue(cur);
Queue<int> depth = new Queue<int>();
depth.Enqueue(0);

List<int[]> history = new List<int[]>();

while (queue.Count > 0) {
cur = queue.Dequeue();
history.Add(cur);
int curDepth = depth.Dequeue();

if (cur.Contains(i)) {
res.Add(i);
resMoves.Add(curDepth);
break;
}
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(" ");
int[] limits = input[0].Split().Select(int.Parse).ToArray();
int[] initial = input[1].Split().Select(int.Parse).ToArray();


int m = limits.Max();
List<int> res = new List<int>();
List<int> resMoves = new List<int>();

for (int i = 0; i <= m; i++) {
int[] cur = initial.ToArray();
Queue<int[]> queue = new Queue<int[]>();
queue.Enqueue(cur);
Queue<int> depth = new Queue<int>();
depth.Enqueue(0);

List<int[]> history = new List<int[]>();

while (queue.Count > 0) {
cur = queue.Dequeue();
history.Add(cur);
int curDepth = depth.Dequeue();

if (cur.Contains(i)) {
res.Add(i);
resMoves.Add(curDepth);
break;
}
6 Replies
Spekulant
Spekulant16mo ago
for (int outOf = 0; outOf < cur.Length; outOf++) {
if (cur[outOf] == 0) {
continue;
}
for (int into = 0; into < cur.Length; into++) {
if (outOf == into) {
continue;
}
if (cur[into] == limits[into]) {
continue;
}

int[] _cur = cur.ToArray();
_cur[into] = Math.Min(cur[into] + cur[outOf], limits[into]);
_cur[outOf] = Math.Max(cur[into] + cur[outOf] - limits[into], 0);
if (!history.Contains(_cur) && !queue.Contains(_cur)) {
queue.Enqueue(_cur);
depth.Enqueue(curDepth + 1);
}
}
}
}
}

for (int ind = 0; ind < res.Count; ind++) {
Console.Write($"{res[ind]}:{resMoves[ind]} ");
}
}
}
for (int outOf = 0; outOf < cur.Length; outOf++) {
if (cur[outOf] == 0) {
continue;
}
for (int into = 0; into < cur.Length; into++) {
if (outOf == into) {
continue;
}
if (cur[into] == limits[into]) {
continue;
}

int[] _cur = cur.ToArray();
_cur[into] = Math.Min(cur[into] + cur[outOf], limits[into]);
_cur[outOf] = Math.Max(cur[into] + cur[outOf] - limits[into], 0);
if (!history.Contains(_cur) && !queue.Contains(_cur)) {
queue.Enqueue(_cur);
depth.Enqueue(curDepth + 1);
}
}
}
}
}

for (int ind = 0; ind < res.Count; ind++) {
Console.Write($"{res[ind]}:{resMoves[ind]} ");
}
}
}
for example if my input is
4 1 1 1 1 1
4 1 1 1 1 1
i should get
0:1 1:0 2:1 3:2
0:1 1:0 2:1 3:2
Jimmacle
Jimmacle16mo ago
and what is the problem?
Spekulant
Spekulant16mo ago
well the program doesnt print out the output it just runs @Jimmacle i dont know where the problem is but it takes the input correctly
Jimmacle
Jimmacle16mo ago
Tutorial: Debug C# code - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Jimmacle
Jimmacle16mo ago
use this to narrow down the problem
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.