i have following doubts regarding c/c++...

1) Is unsigned data types are faster than signed ones? I found them fast on some problems..

2) I had seen some codes which requires operations upto square roots..it looks like.
if(i*i

we can also calculate square root once rather than calculating the product again and again..which one is faster??

3) Is pre-assigning the data in array helps to reduce time..because i found it takes long time in problem DIV

4) which one is faster storing the data and printing at once..or print as we have them..(for integers)

  • created

    Jul '11
  • last reply

    Jul '11
  • 1

    reply

  • 272

    views

  • 2

    users

  1. I'm not certain, but I have never used an unsigned variable on SPOJ.

  2. Calculating the sqrt once would likely be faster to execute, but I haven't seen many problems where this would be an issue, and i*i is faster to type than sort.

  3. Preassigning data would certainly save time in execution. If you mean writing it in your code, then make sure it's correct. That data is difficult to debug. If you mean precalculate before handling test cases, then yes, I do this with my prime sieves all the time or any other data that doesn't change and gets use lots.

  4. Print immediately. Many problems dont define the number of test cases thus making the space complexity impossible. Make sure to use scanf/printf and not cin/cout.

Suggested Topics

Topic Category Replies Views Activity
Off-topic 1 130 Apr 9

Want to read more? Browse other topics in Off-topic or view latest topics.