1797 - I2P(II) 2019_Fall_Chen_hw3 Scoreboard

Time

2019/10/22 18:30:00 2019/11/14 18:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12392 Heatstroke Bamboo Rats 2
12405 Construct tree by inorder and postorder

12392 - Heatstroke Bamboo Rats 2   

Description

This bamboo rat seems to have heatstroke, we might as well ......

── Brothers HuaNong

Brothers HuaNong feed a lot of bamboo rats. They do love to eat bamboo rats! However, some of the rats seems to have heatstroke. Brothers HuaNong couldn't bear to watch them suffer, and we all know how Brothers HuaNong treat those heatstroke rats...


Every bamboo rat has its level of heatstroke(中暑程度), Brother HuaNong would randomly choose a number . If there's a rat with level of heatstroke equals to , Brother HuaNong would think that the rat has heatstroke and eat it.

However, if they just keep eating those heatstroke rats, they would eat up all the rats eventually, so they also have to buy bamboo rats in case that too many rats have heatstroke.

You are hired by Brothers HuaNong. Brothers HuaNong will give you the level of heatstroke of every bamboo rats and several numbers . Your task is to help them find out if there's rats that have heatstroke.


This problem is partial judge. You are going to implement the following functions:

  1. void build_tree(Node **now, int *arr, int l, int r)

    When this function is called, you should build a binary search tree by the array arr.

  2. int query_heatstroke(Node *now, int x)

    This function is used to ask if there exists a node with level equals to x.

  3. void eat_rat(Node **root, int x)

    This function will delete one node with level equals to x.

  4. void buy_rat(Node **root, int x)

    This function will insert a node with level equals to x.


Take sample as an example, initially, the level of heatstroke of the rats would be (1, 8, 309).

  1. heatstroke 8: Exists a rat with level 8, eat it. The sequence becomes (1, 309).
  2. heatstroke 8: No rat with level 8. No dinner tonight.
  3. heatstroke 1: Exists a rat with level 1, eat it. The sequence becomes (309).
  4. heatstroke 309: Exists a rat with level 309, eat it. The sequence is now empty.
  5. buy 5: Add a new rat with level 5. The sequence becomes (5).
  6. heatstroke 5: Exists a rat with level 5, eat it. The sequence is now empty.

 

Input

The first line is an integer n, which indicates the number of bamboo rats.

The next line contains integers, indicate the level of heatstroke of every bamboo rat sorted in ascending order.

The third line is an integer q, which means there are queries below.

There are lines below.

In each queries, there are two operations:

  1. heatstroke x: eat a rat with level equals to if there exists one.
  2. buy x: buy a rat with level equals to x.

0 <= n <= 10^4,  1<= q <= 10^4, 1<= x <= 10^9, the level of bamboo rats have the same range as x.

Output

For each heatstroke operation, output "We might as well eat it." if there's a rat with the corresponding level, otherwise output "No dinner tonight."

Sample Input  Download

Sample Output  Download

Partial Judge Code

12392.c

Partial Judge Header

12392.h

Tags




Discuss




12405 - Construct tree by inorder and postorder   

Description

We will give you the "inorder" and "postorder" of a tree.

You need to print the "preorder" of this tree we give you.

Notice that the the final testcase has small memory limit. If you don't free your tree you will get memory limit exceeded

 

 

 

 

 

(The tree for sample input 1)

(The tree for sample input 2)

Input

There are multiple testcases. The testcases will end with EOF.

Each testcase contains three lines.

First line only contains one integer n(1 <= n <= 100) which means the number of nodes in the tree.

Second line contains n integers which in the range of int. Standing for the "inorder".

Third line contains n integers which in the range of int. Standing for the "postorder".

Output

For each testcase output the "preorder" of the tree.

You have to output in this form:

testcase<id>: <preorder sequence>

Replace <id> and <preorder sequence> into the i-th testcase and the correct preorder sequence.

Each number in preorder sequence should be followed by a single blank(even the last number).

If you have further questions, please refer to sample output.

Sample Input  Download

Sample Output  Download

Tags




Discuss