ACM Algorithm

Volume-I

100 - The 3n+1 Problem[Ad Hoc]
One of the simplest problem in this online judge. Simply follows the problem description. The only trap is this sentence: "between and including i and j". "between" means, process all numbers between i and j if i<j or between j and i if j>i.

102 - Ecological Bin Packing[Ad Hoc, Complete Search]
Brute force, just read the problem description carefully and figure out those 6 (yes, only 6) possible combinations, and then choose the smallest.

113 - Power of Cryptography[Math]
For this problem, better to use pow(10,(log10(p)/n)) rather than exp(log(p)/n)), because the value of log(base 10)(p) is much lesser than log(base e)(p). This one is surely be accepted in C/C++.

136 - Ugly Numbers[Dynamic Programming]
This problem can be solved using:
1. Dynamic Programming, build a list of ugly numbers bottom up, example:
if we know that '1' is the first ugly number and the only prime factors are 2,3,5, then the next ugly number will be min(2*1,3*1,5*1) which is 2.
when we know that '1' and '2' are the first 2 ugly numbers, the next ugly number will be min(2*2,3*1,5*1) which is 3. Note that factor 2 is now multiplied with '2' whereas the rest are still multiplied with '1'.
2. Brute force, enumerate the numbers one by one incrementally, and check whether their prime factors are only 2,3,5... but you have to wait for a very long time. You can just pre-calculate the 1500'th Ugly Number anyway.
3. or you can do a systematic enumeration. See the explanation for problem 443. You can use the same algorithm for this problem. You just need to make some changes as follow:
   1. Loop will be 3 (last loop will be omitted)
   2. max = 2000000000 is OK.
   3. Take the same array size.
   4. Quick Sort will be from 1 to n-1.

146 - ID Codes[Ad Hoc]
Do you confused why I put 1.5 as difficulty rating for this problem? Hehe... if you implement it manually, yes, this finding the next permutation will be a bit complicated. But if you use C++ #include <algorithm> and use the next_permutation() function, the solution for this problem will be extremely short !!!, search the internet to study this cool function :).

Volume-II

256 - Quirksome Squares[Math]
This problem is very easy, since the possible input only either 2,4,6, or 8, simply do a brute force calculation for all those 4 possible input.

264 - Count on Cantor[Math]
A brute force simulation may be possible, but you can solve this problem in a more efficient manner if you can derive the formula. Study the pattern and derive it.

272 - TEX Quotes[Ad Hoc]
"This is bad quote".
`` This is elegant quote ' '
Simply replace all " to their corresponding opening/closing quote, use flag to determine this.

294 - Divisors[Math]
An inefficient program will always give you Time Limit Exceeded. Refer to many mathematic websites and verify this formula:
if the number is a^i * b^j * c^k * ...,
then it has (i+1)(j+1)(k+1)... divisors.


Under construction......................