1422 - I2P(II) 2018_Chen_Midterm_Practice Scoreboard

Time

2018/03/31 23:30:00 2018/04/17 12:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10518 Moving Books
10551 Josephus with Composite
10984 Prefix to syntax tree
11283 rotate linked list
11864 Level Average Numbers of Binary Tree
11868 Zip Unzip

10518 - Moving Books   

Description

The problem is to parse a series of commands to move the books that lie on the table. Initially there are n books lying on the table with book bi adjacent to book bi+1 for all 0 <= i < n-1, as shown in the diagram below:

Book N-1

......

Book 2

Book 1

Book 0

Table


The valid commands and limited for moving books are:

Illegal commands:

  • A = B
  • A or B is not in the range (e.g. You cannot move or remove any book that does not exist)

All illegal commands should be ignored and should have no affect on the configuration of books.


Valid commands:

l   move A on B

Puts book A on book B.                                                                      

As below:

0 1 2 3 4

>> move 1 on 3

0 2 3 1 4

l   move A under B

Puts book A under of book B.

As below:

0 1 2 3 4

>> move 1 under 3

0 2 1 3 4

l   remove A

Remove book A from the list.

As below:

0 1 2 3 4

>> remove 1

0 2 3 4

l   exit

Finish moving the books, print the final status.

 

Input

The input begins with an integer n on a line by itself representing the number of books in the book world. You may assume that 0 < n <= 10000.

The number of books is followed by a sequence of book commands, one command per line. Your program should process all commands until the exit command is encountered.

You may assume that all commands will be of the form specified above. There will be no syntactically incorrect commands.

Output

Your output should contains one line of sequence which represents the order of books from the bottom to the top.

Each number is followed by a single space. And you are asked to add a new line character at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10551 - Josephus with Composite   

Description

The Josephs problem is notoriously known. For those who are not familiar with the problem, among n people numbered 1, 2, . . . , n, standing in circle every mth is going to be executed and only the life of the last remaining person will be saved. Joseph was smart enough to choose the position of the last remaining person, thus saving his life to give the message about the incident.
The persons are eliminated in a very peculiar order; m is a dynamical variable, which each time takes a different value corresponding to the Compositenumbers succession (4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, ...). So in order to kill the i-th person, Josephus cousin counts up to the i-th composite.

A composite number is a positive integer that has at least one positive divisor other than one or the number itself. In other words, a composite number is any integer greater than one that is not a prime number.
For example, there are 6 people in a circle, and the sequence of couting is composite number succession (4, 6, 8, 9, 10, ...).
In the beginning, the step to kill m = 4. The sequence of killing people is as follows.
1, 2, 3, 4.............................(kill 4, and m is changed to 6)
5, 6, 1, 2, 3, 5.....................(kill 5, and m is changed to 8)
6, 1, 2, 3, 6, 1, 2, 3.............(kill 3, and m is changed to 9)
6, 1, 2, 6, 1, 2, 6, 1, 2.........(kill 2, and m is changed to 10)
6, 1, 6, 1, 6, 1, 6, 1, 6, 1.....(kill 1)
Then print 6 as answer.

Input

There will be more than one line, each line with one integer n. n is the number of people. Input terminated by EOF.
Testcase 1 : 1<=n<100
Testcase 2 : 100<=n<1000
Testcase 3 : 1000<=n<5000

Output

The output will consist in separate lines containing the position of the person which life will be saved.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10984 - Prefix to syntax tree   

Description

Given an prefix Boolean expression, which has at most 4 variables ‘A’, ’B’, ‘C’, and ‘D’, and two operators ‘&’ and ‘|’. You have to use this prefix expression to construct a syntax tree.

 

 

  • Syntax tree of |&|AB&CDA

 

You will be provided with main.c and function.h, and asked to implement function.c.

For OJ submission:

        Step 1. Submit only your function.c into the submission block.(Please choose C compiler)

        Step 2. Check the results and debug your program if necessary.

main.c

function.h

 

 

Input

The first line will have a number N with the number of test cases, followed by N lines of input, each contain the prefix Boolean expression.

Output

There are N lines infix expression with necessary parenthesis.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10984.c

Partial Judge Header

10984.h

Tags

10402Mid1



Discuss




11283 - rotate linked list   

Description

Given a link list structure named Node.

 

typedef struct _Node {

    int data;

    struct _Node *next;

} Node;

 

Given a list, rotate the list to the left by k places, where k is non-negative and k is smaller than the count of nodes in linked list.

For example: 
Given 1->2->3->4->5->NULL and k = 3
return 4->5->1->2->3->NULL.

 

Input

The input contains 2 sequence of positive integers.The first sequence is to create a linked list of integers, except the last one, which is -1, indicating the end of the sequence. The second line is an integer k. 

Output

The output contains the sequence of resulting linklist.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11283.c

Partial Judge Header

11283.h

Tags




Discuss




11864 - Level Average Numbers of Binary Tree   

Description

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.

 

e.g.

     3

    /  \

  20    9

        / \

       15  7

 

You should output 3, 14.5, 11.

Input

There are 3 lines for inputs.

The first line contains an integer N , which indicates the number of nodes of the binary tree.

The second line is the inorder traversal of the binary tree.

The third line is the preorder traversal of the binary tree.

Note that there are no duplicated integers in the binary tree.

Output

Print the average of each levels in one line.

1. There is an whitespace between each number. 

2. There is an whitespace after the last number.

3. There is no need to print newline in the end.

Moreover, for the sake of convenience, show only 3 digits after decimal point of each average numbers of level.

(You can simply use %.3f to display in such way)

Sample Input  Download

Sample Output  Download

Partial Judge Code

11864.c

Partial Judge Header

11864.h

Tags




Discuss




11868 - Zip Unzip   

Description

Complete the zip and unzip funciton:

#include "function.h"

#include <stdlib.h>

List* zip(List *lptr1, List *lptr2)
{
   /*your code here*/
}

Pair* unzip(List *lptr)

{

  /*your code here*/

}

 

What zip does is to combine 2 lists.

Elements in corresponding positions form a pair.

Zip function takes the 2 lists as inputs and generates a new list including all the pairs. (2 lists -> a list of pairs)

Note: [ ] means a list, ( ) means a pair
 

e.g.

input 1: [1,2,3]  

input 2: ["a","b","c"]

After zip: [(1,"a"),(2,"b"),(3,"c")]

 

If we zip the result with input 2 again:

[("a",(1,"a")),("b",(2,"b")),("c",(3,"c"))]

 

If we zip the first result with the 2nd result together:

[((1,"a"),("a",(1,"a"))),((2,"b"),("b",(2,"b"))),((3,"c"),("c",(3,"c")))]
 

 

What unzip does is to transform a list of pairs to a pair of lists.

e.g.

input: [(1,"a"),(2,"b"),(3,"c")]

unzip: ([1,2,3],["a","b","c"])
 


input: [("a",(1,"a")),("b",(2,"b")),("c",(3,"c"))] 

unzip: (["a","b","c"],[(1,"a"),(2,"b"),(3,"c")])

 

What we have to do in this problem,

is to zip 2 lists N times and do unzip 1 time to output the final pair.
 

Input

5 lines

1st line: M1 (number of 1st list's elements)

2nd line: M1 elements of 1st list

3rd line: M2 (number of 2nd list's elements)

4th line: M2 elements of 2nd list

5th line: N (times to do zip)

Output

One line. The final result of pair after N times of zip and 1 time of unzip. Remeber the new line in the end.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11868.c

Partial Judge Header

11868.h

Tags




Discuss