Eeee4's blog

By Eeee4, history, 5 weeks ago, In English,

Hi, I'm relatively new to competitive programming, in fact, I'm quite new to programming itself. So while I have learned basic concepts such as if else, and arrays, I know there is much more to learn. But I think right now, I need to learn more functions and what they do. For example, math.max() is a function I never knew, and I would be glad if someone could give me some functions that you believe are important for cp.

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

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

What is your programming language?

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    java

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      If you are very beginner, learn C++. Most people uses it and you will get much more help if you use C++.

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        On the contrary, java has better readability and bug tracking to the exact line number and type of error, so it's much better for beginners.

»
5 weeks ago, # |
  Vote: I like it -13 Vote: I do not like it

learn the static method Code.better()

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I would suggest learning to code first before starting competitive programming. Competitive programmers aren't known for writing good code, and there aren't that much resources for learning to code on competitive programming sites. Maybe go through the official Java tutorial. Also, know that C++ is typically considered to be more suited for competitive programming, although many would say it's harder to learn for beginners.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Fast input and output is necessary. Look at Petr Java submissions for a template (just delete the all the code except the I/O code). In general, look at top Java user's submissions to learn Java functions. I think C++ is cleaner to write than Java, so I stopped using Java.

»
4 weeks ago, # |
Rev. 2   Vote: I like it +2 Vote: I do not like it

The ones I used most often (in roughly this order) are:

  • Math.max()/Math.min()
  • Arrays.fill()
  • Collections.sort()
  • Integer.compare(), Long.compare(), Double.compare() for implementing Comparable
  • Arrays.sort() Careful! this is n^2 on primatives! Check out my submissions for how to fix it
  • Collections.shuffle() //this one is shandom_ruffle in C++
  • new StringBuilder(someString).reverse() for reversing a string on hyperbangers
  • overriding the toString method for objects for better debugging

**You can get ~25% faster Math.max() or Math.min() calls by writing your own max or min function. Calling static methods from another class is unreasonably slow for some reason, so if you are really tight on time and that is the only time consuming thing you are doing, maybe write the ternary version yourself. Bitmask stuff

  • Integer.highestOneBit()
  • Integer.lowestOneBit() //or x&-x
  • Integer.bitCount()
  • Integer.numberOfTrailingZeros()
  • Integer.numberOfLeadingZeros()

** all have Long.whatever() too

Also important java basics include:

  • ArrayLists
  • TreeSets/TreeMaps (TreeSet.first(), TreeSet.last(), TreeSet.lower/higher/floor/ceil)
  • HashSets/HashMaps + custom hashing + equals method
  • PriorityQueues
  • Custom Sorting with implements Comparable or with lambdas

I'm probably forgetting a few, but these are the main ones that come to mind.