767 - 103 資料結構導論 作業三 Scoreboard

Time

2015/05/18 00:00:00 2015/06/22 23:59:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10601 preorder traversal
10602 level-order traversal
10603 8 queens
10651 Binary Search Tree II
10658 Binary Search Tree

10601 - preorder traversal   

Description

Given a tree G(VE) with at most N nodes, print its preorder traversal sequence. Each node is labeled by a unique integer number from 1 to N, and in case that the node has more than one child, the one who is labeled by smaller number should be visited first. Root node is always node 1.

 

Input

Input begins with an integer T, the number of test cases. Each test case would be in the following format.
Line 1: An integers: N, means the size of the tree.
The following are N-1 lines.
Line i (2<=i<=N): Two integers: x y, separated by a blank, indicating that x and y are connected.

Limit : N<=1000

Output

For each test case outputs one lines, the preorder traversal sequence.

Each node number should be separated by one space.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10602 - level-order traversal   

Description

Given a tree G(VE) and its root, print its level-order traversal, where we visit all of the nodes at the same level before going to the lower ones. Each node is labeled by a unique integer number, and in case that the node has more than one child, the one who is labeled by smaller number should be visited first.

Input

The first line of input is a single integer T (T ≤ 100), denoting the number of test cases. Each test case started with an integer pair N (N ≤ 1000) and R, indicating the number of nodes and the root number respectively. The following N - 1 lines contain pairs of integers ui and vi (1 ≤ uivi ≤ N), each in a line, which means ui and vi are adjacent.

Output

For each test case, output “Case i:” denoting the traversal of i-th test case on a line. Then, for each visited node, started from the root, print the labeled number. Every two successive numbers are separated by a space characters. Print a blank line between test cases.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10603 - 8 queens   

Description

Each chessboard has numbers in the range 1 to 99 written on each square and is supplied with 8 chess queens. The task is to place the 8 queens on the chess board in such a way that no queen threatens another one, and so that the sum of the numbers on the squares selected is the maximum . (For those unfamiliar with the rules of chess, this implies that each row and column of the board contains exactly one queen, and each diagonal contains no more than one queen.)

Write a program that will read in the number and details of the chessboards and determine the highest scores possible for each board under these conditions.

Input

Input will consist of K (the number of boards), on a line by itself, followed by K sets of 64 numbers, each set consisting of eight lines of eight numbers. Each number will be a non-negative integer less than 100. Each case is separated by a blank line. There will never be more than 20 boards.

Output

The outputs of all test cases should be printed in order. For each test case a line, print the highest score.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10651 - Binary Search Tree II   

Description

In this problem, you are to implement a binary search tree
with insert, traverse, delete operation.
The rules of delete is as follows:
(1) If deleting a node X without any children (i.e., deleting a leaf),
  the new tree will simply remove X.
(2) If deleting a node X with exactly 1 child C,
  (i)  If X is the root, simply remove X and make C the root of the new tree.
  (ii) Else, simply remove X and connect parent of X to C in the new tree.
(3) Else, we delete a node X with 2 children.
  Then, swap X with the successor, and then delete X (similar to the
  description in the lecture notes).

Input

There are only one test case, and the input will terminate with an EOF.
In the test case, there will be several operations (no more than 100000).
Each operation occupies a line.
"Insert X" means to insert X (number) into the BST.
"Delete X" means to delete X from BST, if X does not exist in the BST then nothing should be done.
"Traverse" means to traverse the BST in preorder.
All numbers are positive and not greater than 100000.
No duplicated number will be inserted into BST.
Assume the BST is empty at initial.

Output

For "Traverse" operation, output a line contains your traverse progress in the BST and seperate each
number with a space.
If the BST is empty, you should still output an empty line.

Sample Input  Download

Sample Output  Download

Tags

1 2



Discuss




10658 - Binary Search Tree   

Description

In this problem, you are to implement a binary search tree
with insert only operation

That is, insert a1,a2,...,ain order

Finally, output the preorder of the BST

Input

The first line is an integer T, the number of testcases.

For each testcase:
The first line is an integer n , the number of numbers to be inserted
The second line n positive integers a1,a2,...,an (numbers are distinct)

n, ai<=1000

Output

輸出一行以空白隔開BST的preorder 行末不要空白

Example:
for(i=0; i<100; i++){
    if(0<i)printf(" ");
    printf("%d",num[i]);
}
printf("\n");

Sample Input  Download

Sample Output  Download

Tags




Discuss