humble19's blog

By humble19, history, 2 years ago, In English

Hey I am beginner in cp and java , can anybody help in learning all the important things of java that can help in cp. If you guys have any roadmap with detail and links of all important thing.(for Java)please provide in comment. Thank you.

  • Vote: I like it
  • -13
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
  Vote: I like it +3 Vote: I do not like it
  • »
    »
    2 years ago, # ^ |
      Vote: I like it +26 Vote: I do not like it

    No it won't, it's from GeeksForGeeks.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it +20 Vote: I do not like it

      To detail —

      • It appears to be a bunch of random tricks, it's certainly not some "roadmap" that OP asked for.
      • 1 and 2 are not "faster", at least any reasonable compiler should be smart enough to optimize %2, *2 and /2.
      • 3 is useless as well, it may be "cooler" but it is not really faster (yes, it uses more memory but whatever it does is negligible).
      • 4 and 5 are links to gfg articles and therefore useless.
      • 6 and 7 are probably wrong, at least I don't trust Math.log10 to be precise enough for every 64-bit number.
      • 8 is alright I suppose, but a pretty random detail.
      • »
        »
        »
        »
        2 years ago, # ^ |
        Rev. 3   Vote: I like it 0 Vote: I do not like it

        While I agree that any reasonably smart compiler should optimize operations in 1 and 2, interestingly, as I can see on Compiler Explorer, Java does not. It's less readable and somewhat more prone to error than standard arithmetic, but using it in a tested template should be fine. Then again, I doubt that a beginner is going to start out with a custom CP template right away.

        Also to add, not only is 3 less readable, it is dangerous to use as well. It may work for swapping int variables, but in cases where array elements are to be swapped based on indices, for example, arr[i] and arr[j], it is essentially a bug when i and j are equal... (Why? Exercise for the readers)

        • »
          »
          »
          »
          »
          2 years ago, # ^ |
            Vote: I like it +3 Vote: I do not like it

          thanks, I didn't realise it's buggy when swap element in array.

      • »
        »
        »
        »
        2 years ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        Well, you're right that any reasonable compiler should optimize %2, etc, but from my experience as a Java programmer it does make a huge difference in some cases.

»
2 years ago, # |
  Vote: I like it +3 Vote: I do not like it

You can use Usaco Guide. In settings options you can choose the language to Java and Get Started

»
2 years ago, # |
  Vote: I like it +9 Vote: I do not like it

CF allows you to read others' submissions from the archives, just check the accepted submissions and filter by language. It'll be best to refer to codes by high-rated coders since they generally have a clearer understanding of the problem and write less redundant code (except for the template of course).

Lastly, for resources — refer to the Catalog. Additionally, if you're really interested, and, invested, read relevant blogs by the top contributors. (They're top contributors for a reason — their content: blogs/comments are usually very helpful).