Cut the Tree
There is an undirected tree where each vertex is numbered from 1 to n, and each contains a data value. The sum of a tree is the sum of all its nodes' data values. If an edge is cut, two smaller trees are formed. The difference between two trees is the absolute value of the difference in their sums. Given a tree, determine which edge to cut so that the resulting trees have a minimal difference between them, then return that difference. The minimum absolute difference is . Note: The giv
View Solution →Making Candies
Karl loves playing games on social networking sites. His current favorite is CandyMaker, where the goal is to make candies. Karl just started a level in which he must accumulate candies starting with machines and workers. In a single pass, he can make candies. After each pass, he can decide whether to spend some of his candies to buy more machines or hire more workers. Buying a machine or hiring a worker costs units, and there is no limit to the number of machines he can own or workers h
View Solution →Gena Playing Hanoi
The Tower of Hanoi is a famous game consisting of rods and a number of discs of incrementally different diameters. The puzzle starts with the discs neatly stacked on one rod, ordered by ascending size with the smallest disc at the top. The game's objective is to move the entire stack to another rod, obeying the following rules: Only one disk can be moved at a time. In one move, remove the topmost disk from one rod and move it to another rod. No disk may be placed on top of a smaller disk.
View Solution →Beautiful Quadruples
We call an quadruple of positive integers, , beautiful if the following condition is true: Note: is the bitwise XOR operator. Given , , , and , count the number of beautiful quadruples of the form where the following constraints hold: When you count the number of beautiful quadruples, you should consider two quadruples as same if the following are true: They contain same integers. Number of times each integers occur in the quadruple is same. For example and should be considered
View Solution →Red Knight's Shortest Path
In ordinary chess, the pieces are only of two colors, black and white. In our version of chess, we are including new pieces with unique movements. One of the most powerful pieces in this version is the red knight. The red knight can move to six different positions based on its current position (UpperLeft, UpperRight, Right, LowerRight, LowerLeft, Left) as shown in the figure below. The board is a grid of size . Each cell is identified with a pair of coordinates , where is the row number
View Solution →