ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1282. Game Tree

So easy ! In this website, there are many problems similar to this problem. So, it costs me no efforts to solve it !
Posted by Phan Hoài Nam (Harvey Nash) 24 Feb 2011 15:14
Hint for you :

int travel(int player,int node)
{
    int value;

    if(isLeaf(node)) return getValue(node);

    // If the first player is at this node, he prefer getting the maximal value among -1, 0 and +1.
    if(player == 0)
    {
        value = MinValue();
        for(int a=0;a<numberOfChild(node);a++)
        {
            int v = travel((player+1)%2,getChild(node,a));
            if(value < v) value = v;
        }
    }
    // Get the minimal value.
    else
    {
        value = MaxValue();
        for(int a=0;a<numberOfChild(node);a++)
        {
            int v = travel((player+1)%2,getChild(node,a));
            if(value > v) value = v;
        }
    }
    return value;
}

Edited by author 24.02.2011 15:14