Tuesday, May 08, 2007

ACM101-The Blocks Problem

Level : 35/100
Concept : Basic Data Structure, Link List Theory, and.... clear mind.
Noticeable Point :
  1. Some complex and reusable code can be extracted as a inline function.
  2. Modularize helps a lot.
Method :
  • Main concept of this solution is not hard. First, we make a structure of each block with these elements :
    1. box* uplink and box* downlink, these two pointer points to upper and lower block in the pile. If uplink == NULL means it is the top of the pile. If downlink == NULL means it is the lowest block in the pile, or alone, and IT STAND ON THE ORIGINAL PLACE.
    2. static int BoxID. This indicates where the original place is, and the number of the block. In fact, by the problem saying, if a block.downlink = NULL, it MUST on its original place, as BoxID.
    3. Constructor and Destructor, which are supposed to control BoxID.
  • Define the function respectively. For example, we can draw a blueprint of procedure that "Move Over" does. First, we find that it need a function to clear all boxes above target, so we must make a clearup(). The procedure is simple, clearup() both target and destination, move target to the top of destination. Then, we must make clearup(), how it does? we find that we need a function to get the top box's position, so we must make a box* gettop(). Do this again and again we will get every function ready. In my works, I have made MoveOnto(), MoveOver(), PileOnto(), PileOver(), gettop(), clearup().
  • Then assemble these components up. It is not very easy to debug, we must do a hard labor to make sure these works fine. Then, output module seems not complex, do it and debut this patiently... yes you will need lots of patient.

ACM100-The 3n+1 Problem

Level : 12/100
Concept : None
Noticeable Points :

  1. Output order must be same to input order
  2. swap is NOT default function of GCC
Method : Brute, anyway :)

The 3n+1 problem

Traditional Chinese Version(Lucky's ACM)