Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is map[(int)x]++;What it does?
    primarykey
    data
    text
    <p>Hey I took part in Facebook Hacker Competition and I got a solution of this question. I solved th question in order O(K^2) but this guy solved it in O(^K). Please explain me what the code doing.</p> <pre><code> import java.io.File; import java.util.Scanner; public class FindTheMin { private long getNextMin(long[] map, long start, long k) { while (map[(int)(start)] &gt; 0) start++; return start; } public long findNth(long n, long k, long a, long b, long c, long r) { long[] cache = new long[100010]; long[] map = new long[100010]; long pre = a; for (int i = 0; i &lt; k; i++) { long num; if (i == 0) num = a; else num = (b * pre + c) % r; cache[i] = num; if (num &lt;= k + 1) map[(int) num]++; pre = num; } pre = getNextMin(map, 0, k); cache[(int)k] = pre; map[(int)pre]++; for (int i = 0; i &lt;= (int)k; i++) { long deque = cache[i]; if (deque &gt; k) { long x = getNextMin(map, pre, k); cache[i] = x; map[(int)x]++; pre = x; } else { if (deque &lt; pre) { if(map[(int)deque] == 1) { cache[i] = deque; pre = deque; continue; } } map[(int)deque]--; long x = getNextMin(map, pre, k); cache[i] = x; pre = x; map[(int)x]++; } } return cache[(int)((n - 1) % (k + 1))]; } public static void main(String[] args) { try { Scanner s = new Scanner(new File("in.txt")); int m = s.nextInt(); FindTheMin f = new FindTheMin(); for (int i = 1; i &lt;= m; i++) { int n, k, a, b, c, r; n = s.nextInt(); k = s.nextInt(); a = s.nextInt(); b = s.nextInt(); c = s.nextInt(); r = s.nextInt(); System.out.println("Case #" + i + ": " + f.findNth(n, k, a, b, c, r)); } } catch (Exception e) { e.printStackTrace(); } } } </code></pre> <p>And what are the best ways to learn things like this. the best way to learn java? This was the question <a href="https://www.facebook.com/hackercup/problems.php?pid=494433657264959&amp;round=185564241586420" rel="nofollow">https://www.facebook.com/hackercup/problems.php?pid=494433657264959&amp;round=185564241586420</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload