Go to advanced javascript settings in ubuntu at Edit->Preferences->Content->Advanced (next to "Enable javascript")-> uncheck the "Disable or replace context menus".
But sometimes the right button menu does not show up. Really disappointed! I will update when I find a better solution.
Looks like google Chrome does not have this problem.
Sunday, April 14, 2013
project euler problem 107
Minimal network
This is a simple minimum spanning tree problem. The algorithm is readily found in CLRS. I checked my old code, it runs pretty fast, but I wrote my own version of minheap. This time, I used STL's maxheap. It helps to reduce 40% of the code. But I found my old code runs faster.
This is a simple minimum spanning tree problem. The algorithm is readily found in CLRS. I checked my old code, it runs pretty fast, but I wrote my own version of minheap. This time, I used STL's maxheap. It helps to reduce 40% of the code. But I found my old code runs faster.
Saturday, April 13, 2013
project euler problem 364
Comfortable distance
This problem is not a very difficult one. But in my opinion, it is not easy.
When I first tried to solve this problem, the first and the last seat are quite troublesome. I also felt that occupancy of one seat would affect its neighbors, so it was difficult to use dynamic programming method.
I thought it over and finally found that this was just an relatively complicated combination problem. Several different situations needs to be handled. In each situation, it is relatively easy to find the number of ways to make all people seated following the rule.
My code's efficiency is not too bad. It takes less than 0.6 second to get the correct answer.
This problem is not a very difficult one. But in my opinion, it is not easy.
When I first tried to solve this problem, the first and the last seat are quite troublesome. I also felt that occupancy of one seat would affect its neighbors, so it was difficult to use dynamic programming method.
I thought it over and finally found that this was just an relatively complicated combination problem. Several different situations needs to be handled. In each situation, it is relatively easy to find the number of ways to make all people seated following the rule.
My code's efficiency is not too bad. It takes less than 0.6 second to get the correct answer.
Friday, April 12, 2013
project euler problem 334
Spilling the beans
An interesting problem!
I spent several hours on this problem, but failed to find any clue. I wrote a brute force solution for it, checked the number of moves required when the number of beans are small in each bowl(two bowls for example). I found some analytical formula for any number of beans in only two bowls, but all futile. Since the problem ask for 1500 bowls, the total number of beans is about 1.5 million! The largest headache I found is to determine the position of the empty bowl.
I played the game again and again on papers, those empty bowls are killing me! Finally I found a solution to make number of empty bowls at minimum. But my program is too slow. After some time, I found how to make it efficient. The trick is simple, we need to do as much analytical work as we can, leave the task for the computer easy and simple.
It only takes my notebook 0.03 second to get the answer! Isn't that kidding?! I spent a couple of days working for the computer and leave it only 30 millisecond's work.
I really enjoyed in solving the problem. This is the glamour of project euler!
An interesting problem!
I spent several hours on this problem, but failed to find any clue. I wrote a brute force solution for it, checked the number of moves required when the number of beans are small in each bowl(two bowls for example). I found some analytical formula for any number of beans in only two bowls, but all futile. Since the problem ask for 1500 bowls, the total number of beans is about 1.5 million! The largest headache I found is to determine the position of the empty bowl.
I played the game again and again on papers, those empty bowls are killing me! Finally I found a solution to make number of empty bowls at minimum. But my program is too slow. After some time, I found how to make it efficient. The trick is simple, we need to do as much analytical work as we can, leave the task for the computer easy and simple.
It only takes my notebook 0.03 second to get the answer! Isn't that kidding?! I spent a couple of days working for the computer and leave it only 30 millisecond's work.
I really enjoyed in solving the problem. This is the glamour of project euler!
Wednesday, April 10, 2013
project euler problem 104
Pandigital Fibonacci ends
I reviewed my old code today, it is ugly. I kept all digits in a vector, which finally contains a n X 10,000 of digits, where most of them are useless. This time, I only kept the last 9 digits.
I compared my old code with my new code.
Old code: 20 seconds;
New code: 0.144 second;
The difference is huge!
There is another problem which is quite similar to this problem but much more difficult to solve. Problem 399
I reviewed my old code today, it is ugly. I kept all digits in a vector, which finally contains a n X 10,000 of digits, where most of them are useless. This time, I only kept the last 9 digits.
I compared my old code with my new code.
Old code: 20 seconds;
New code: 0.144 second;
The difference is huge!
There is another problem which is quite similar to this problem but much more difficult to solve. Problem 399
project euler problem 103
Special subset sums: optimum
I do not like this problem too much. It seems that everyone is using brute force method. The problem cannot be easily generalized to n = 10 or larger numbers.
I do not like this problem too much. It seems that everyone is using brute force method. The problem cannot be easily generalized to n = 10 or larger numbers.
project euler problem 102
Triangle containment
This problem is great! I used very complicated logic in my code. I got the correct answer after I fixed one tricky bug in my code. Then I checked the discussion thread. I found two interesting algorithms. First, how to calculate the area of the triangle given the coordinates of vertices. Second, how to solve this problem efficiently. I feel awful that I missed these algorithms for more than a year!
This problem is great! I used very complicated logic in my code. I got the correct answer after I fixed one tricky bug in my code. Then I checked the discussion thread. I found two interesting algorithms. First, how to calculate the area of the triangle given the coordinates of vertices. Second, how to solve this problem efficiently. I feel awful that I missed these algorithms for more than a year!
Subscribe to:
Posts (Atom)