Now, since Python is really gaining reputation among competitive programming also. What are some particular types of problem that are easier to code in Python compared to C++/JAVA?
From my personal experience in Competitive Programming and Python…
Python mostly passes and become a boon to Competitive Programming when the number range is big such as FCTRL2 on the contrary I have evaluated that Python mostly fails where the input file is big, though this totally depends on the type of question and the approach… but If we see some problems like HDELIVER, where the large input was the major problem as I found the cause…
The major type of problems in which people prefer C/C++ over Python as I have seen are during the implementation of complex Data Structures including Graphs, Trees, etc… though as a matter of fact, “If u know an reasonable algorithm, you can implement it in any language u like”… but another fact is Python is slow so it is mostly avoided at times…
I guess that the most direct answer is:
In fact, in my opinion Python is good to work on problems where you only need to implement some sort of mathematical formula, or on problems where use of modulo operator is heavily required (since you can be careless with this over the intermediate calculations, which is something bad in my opinion).
Other than that, even for problems where BigInts are present, sometimes speed of execution can really be a bottleneck that even the speedup factor can’t make up for.
So, my advice is, is you arrived at a direct formula and don’t want to waste time on syntax issues, use Python, else use anything that’s compiled to gain speed of execution.
String manipulation is quite easy as well.Splitting strings etc are as easy as eating a pie.I still remember me and my friend making jokes that if u want to do an operation in python guess the word closest to that operation turns out it works 80 percent of the time.But i would like to caution u that some programs are meant so the easy looking Python solutions fail.(Complexity at the cost of speed).for example:http://www.spoj.com/problems/MUL/
Python is very slow and might not get accepted in some cases where number of test cases/ iterations are large. check out these 2 solutions which are almost identical for June-cook off problem ATTIC. 1st in C and 2nd in python.
Python one gave TLE while C one ran in 0.34 secs when time limit for problem was 3.5 seconds.Normally solutions of same complexity get accepted but i guess sometimes Python is just too slow.i have found python to be very slow on function calls, however its great for strings, large numbers, inbuilt functions like sort, count,etc.
Problems that manipulate sets.
Python is an object oriented script language while C++ is an object oriented compiling language. As well as difference from scripting and compiling, there might be several advantages and disadvantages between each other.
Here are some foundational differences.
1.)Memory management: C++ doesn’t have garbage collection, and encourages use of raw pointers to manage and access memory. It differentiates between heap and stack, and it requires you to attend to values versus references. C++ requires much more attention to bookkeeping and storage details, and while it allows you very fine control, it’s often just not necessary.
2.)Types: C++ types are explicitly declared, bound to names, checked at compile time, and strict until they’re not. Python’s types are bound to values, checked at run time, and are not so easily subverted. Python’s types are also an order of magnitude simpler. The safety and the simplicity and the lack of declarations help a lot of people move faster.
3.)Language complexity: C++ is a beast of a language. The spec is 775 pages of language legalese, and even the best C++ developers I’ve known can be caught up short by unintended consequences in complex (or not so complex) code. Python is much simpler, which leads to faster development and less mental overhead.
4.)Interpreted vs compiled (implementation): C++ is almost always explicitly compiled. Python is not (generally). It’s common practice to develop in the interpreter in Python, which is great for rapid testing and exploration. C++ developers almost never do this, gdb notwithstanding.
Based on advantages and disadvantages of languages in different condition choose that one which help us to solve problem .
Problems where u need factorials and involving big calculations like 100! or Combinations and permutations …This problems can be easily solved in python…
hmmm… your Python solution is slow because it is in O(n^2) worst-time.
modifying the index inside the for loop doesn’t change it for the next iteration, it’s a matter of scope.
you can simply add a debug print on stderr to see i increasing one by one.
try with a while-loop
http://www.codechef.com/viewsolution/2298014 you’ll get AC as well.