2791 - DS_2023Spring_Lab3 Scoreboard

Time

2023/05/01 18:30:00 2023/05/01 20:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
13900 Yu Gi Oh Simulator

13900 - Yu Gi Oh Simulator   

Description

Background Story

You are a fan of yu-gi-oh but you don’t have yu-gi-oh card.
Therefore, you can only utilize poker cards to simulate simple yu-gi-oh.

Simple Rule Explanation

  • Every turn, you will draw a card from a deck of cards then put it on table.

  • You can only put two cards on table(left and right side).

  • each card has its pattern:

    • Clubs♣️:

      • directly put it on table from left to right(if there is a card on left side then put it to right).
      • It contains 1 point.
    • Diamonds♦️:

      • it should cover on a card.
      • if the covered card is on left side then the covered card will be the left child node of this card, vice versa.
      • if both of the cards on table contain same points, then Diamonds will cover on the left side first.
      • Diamonds♦️ will cover the lowest point card first.
      • It contains 3 points
    • Heart♥️:

      • it should cover on two cards(left side and right side of table).
      • left side card will be its left child node, and right side card will be its right child node.
      • whenever putting this card, we sum the points from its left child nodes and right child nodes.
      • the points sum from its left child and all left child’s child become positive(+), and the points sum from its right child and all right child’s child become negative(-).
    • Spade♠️: whenever you draw this card the game is over.

  • In the end, you need to sum the values from all Heart♥️.

    • Some extra hints:
      • If the card you draw cannot be put because of missing conditions. For example: you draw a Diamonds♦️ but there is no card on left side and right side, you will just ignore the card.

Simple Demonstration

  • The turns You decides will be like:
Clubs
//first turn you put a clubs on left side of table.
//table(clubs, )
//structure:
        table
      /
    Clubs

Clubs
//second turn you put a clubs on right side of table.
//table(clubs, clubs)
//structure
        table
      /      \
    Clubs   Clubs

Diamond
//third turn you cover a Diamond on left side of Clubs.
//Clubs on left side becomes a left child node of Diamond
//table(Diamond, clubs)
//structure
        table
      /      \
  Diamond   Clubs
    /
 Clubs

Heart
//Fourth turn you cover a Heart on both of side of cards 
//it will be placed on the left side.
//calculate the sum value from left(4) and right(-1) = 3
//table(Heart, )
//structure
            table
            /
         Heart(3+1-1=3)
      /         \
  Diamond(3)   Clubs(-1)
    /
 Clubs(1)


Clubs
//Fifth turn you put a Clubs on right side 
//table=(Heart, Clubs)
//structure
            table
            /    \
         Heart  Clubs
       /      \
  Diamond   Clubs
    /
 Clubs


Heart
//Sixth turn you cover a Heart on both side
//Each of side of card become its child node.
//calculate the sum value from left and right = 7
//table(Heart, )
//structure
                  table
                  /
              Heart(3+3+1+1-1=7)
            /    \
     Heart(3)  Clubs(-1)
       /     \
  Diamond(3) Clubs(1)
    /
 Clubs(1)



Heart
//seventh turn you cannot put Heart because there is only one card on table.
//just ignore this card

Clubs
//eighth turn you put a Clubs on right side 
//table=(Heart, Clubs)
//structure
                  table
                  /    \
              Heart    Clubs
            /    \
       Heart     Clubs
       /     \
  Diamond   Clubs
    /
 Clubs



Diamond
//nineth turn you cover a Diamond on right side of Clubs since the level
//table(Heart, Diamond)
//structure
                  table
                  /    \
              Heart    Diamond
            /    \        \
       Heart    Clubs    Clubs
       /    \
   Diamond   Clubs
    /
  Clubs



Spade
//Endtag, the game is over

  • Now you need sum all the Heart value in your tree: 3+7=10
                  table
                  /    \
              Heart(7) Diamond
            /    \        \
       Heart(3)  Clubs    Clubs
       /         \
   Diamond       Clubs
    /
  Clubs

Your output need to be 10\n(\n means a new line)!

Input

Clubs
Clubs
Diamond
Heart
Clubs
Heart
Heart
Clubs
Diamond
Spade

Output

10

Sample Input  Download

Sample Output  Download

Tags

Tree Tree traversal



Discuss