Key to solve:
I'd say "Understand the English" is the key. The movement is as follows:
two blocks on the same positoin should take no action.
stack n onto its intial position means push n onto the position[n].
move a onto b: stack thoses blocks above a and b onto their initial positions. Then stack a above b.
move a over b: stack thoses blocks on top of a onto their initial positiond. Then stack a on top of b.
pile a onto b: stack thoses blocks above b onto their initial positiond. Then stack thoese blocks above a and includes a above b, keeping order.
pile a over b: stack thoese blocks above a and includes a on top of b, keeping order.
Here is the code to simulate the movement
if (locations[a] != locations[b])
{
// pop out top of b
// a and b are on different stack
isMove = strcmp ("move", action) == 0;
isOnto = strcmp ("onto", param) == 0;
if (isMove)
{
if (isOnto)
{ // move a onto b
//pop out top of b
stackno = locations[b]; //select the stack contains a
top = size[stackno] - 1;// index of the topmost block on that stack
// pop out a block from the top until there is no more block or a is met
while (top >= 0 && blocks[stackno][top] != b)
{
box = blocks[stackno][top--]; // take out the block
--size[stackno];// pop out the topmost box
blocks[box][size[box]] = box; // puts on top of its initial positions
++size[box];
locations[box] = box;
}
//pop out top of a
stackno = locations[a]; //select the stack contains a
top = size[stackno] - 1;// index of the topmost block on that stack
// pop out a block from the top until there is no more block or a is met
while (top >= 0 && blocks[stackno][top] != a)
{
box = blocks[stackno][top--]; // take out the block
--size[stackno];// pop out the topmost box
blocks[box][size[box]] = box; // puts on top of its initial positions
++size[box];
locations[box] = box;
}
// assert blocks[stackno][top] is a
--size[locations[a]];
blocks[locations[b]][size[locations[b]]++] = a;
locations[a] = locations[b];
}
else
{
//pop out top of a
stackno = locations[a]; //select the stack contains a
top = size[stackno] - 1;// index of the topmost block on that stack
// pop out a block from the top until there is no more block or a is met
while (top >= 0 && blocks[stackno][top] != a)
{
box = blocks[stackno][top--]; // take out the block
--size[stackno];// pop out the topmost box
blocks[box][size[box]] = box; // puts on top of its initial positions
++size[box];
locations[box] = box;
}
--size[locations[a]];
// put a on top of the top of b
blocks[locations[b]][size[locations[b]]] = a;
++size[locations[b]];
locations[a] = locations[b];
}
}
else
{
if(isOnto)
{
//pop out top of b
stackno = locations[b]; //select the stack contains a
top = size[stackno] - 1;// index of the topmost block on that stack
// pop out a block from the top until there is no more block or a is met
while (top >= 0 && blocks[stackno][top] != b)
{
box = blocks[stackno][top--]; // take out the block
--size[stackno];// pop out the topmost box
blocks[box][size[box]] = box; // puts on top of its initial positions
++size[box];
locations[box] = box;
}
}
// pile a onto b
stackno = locations[a]; //select the stack contains a
top = 0;
while (blocks[stackno][top++] != a);
//top is the index of a;
// cop from a to its top to b stack
for (i = top - 1; i < size[stackno]; ++i)
{
blocks[locations[b]][size[locations[b]]++] = blocks[stackno][i];
locations[blocks[stackno][i]] = locations[b];
}
size[stackno] = --top;
}
Key to solve:
What will happen when two surfaces contact each other? The spacing between them is 0. In other words, the spacing is all consumed. The question is changed to ask what is the minimum spacing between each row of the two surfaces. When you get that minimum, all you have to do is to subtract it by the spacing of each rows. That is your anwser.
Key to solve:
How to do division by hands? For example, 111 / 3, you will do 1/3 first, then 11/3. Another example, 1111/56, you will do 1/56, 11/56, 111/56. Get it yet?
one = 1;
dividen = 1;
while (1)
{
remainder = dividen % n;
if (!remainder)
{
break;
}
++one;
dividen = remainder * 10 + 1;
}
Key to solve:
Treat every single category as a large array of course codes. To see wheather the minumum number of course has taken or not, just go through every selected courses, count the number of fullfilment. Then repeat this process for every category.
Note: Without early break of checking
for (j = 0; j < ncourse; ++j)
{
if (table[mychoice[j]] == 1)
{
--min;
}
}
fulfil = min <= 0;