22 Two Printers

Back to Problem Solutions forum

dimonos05psy     2017-02-05 18:38:02

Help is already all head broke :( Why is the same formula of the responses correctament, and some do not. Expected answer was: 123773549 142848551 252588560 166009005 399504768 247194948 320053772 358744500 86612299 258477528 203573364 154941495 30277420 388518366 34530380 53940285 Your answer was: 123773549 143084886 252588560 166010040 399504768 247194948 320053772 358744500 86612299 258484738 203573364 154941495 30277420 388518366 34530380 53940465

Code: foreach (string item in s) { int[] arr = item.Split(' ').Select(x => int.Parse(x)).ToArray(); int p1 = (int)SqlDecimal.Round((SqlDecimal)arr[1] * arr[2] / (arr[0] + arr[1]), 0); int p2 = (int)SqlDecimal.Round((SqlDecimal)arr[0] * arr[2] / (arr[0] + arr[1]), 0); int time1 = p1 * arr[0]; int time2 = p2 * arr[1]; if (time1 > time2) Console.Write(time1 + " "); else Console.Write(time2 + " "); }

Sorry for my English:)

dimonos05psy     2017-02-05 18:42:03

<pre><code>

        foreach (string item in s)
        {
            int[] arr = item.Split(' ').Select(x => int.Parse(x)).ToArray();
            int p1 = (int)SqlDecimal.Round((SqlDecimal)arr[1] * arr[2] /
                (arr[0] + arr[1]), 0);
            int p2 = (int)SqlDecimal.Round((SqlDecimal)arr[0] * arr[2] /
                (arr[0] + arr[1]), 0);
            int time1 = p1 * arr[0];
            int time2 = p2 * arr[1];
            if (time1 > time2)
                Console.Write(time1 + " ");
            else
                Console.Write(time2 + " ");
        }
        Console.Read();
    }
}

</code></pre>

tonychamberlain     2017-02-05 19:25:29

You probably shouldn't post code as it might be against the spirit of the site. Though there doesn't seem to be a way to post messages directly to other users.

As far as you problem check out the example code of 3 5 4. The answer should be 9. I believe your code will return 10. Hint: Your code always returns the exact answer if both printers finish together, or your letting the slower printer finish(thats why your answers are too big).

Second Hint: Maybe Floor and underestimating instead of round. (you might have to do some extra work to figure out the last bit)

dimonos05psy     2017-02-06 19:50:05

Solution done:) The problem was in round-up and a couple of conditions.

Please login and solve 5 problems to be able to post at forum