1280 - 106學年上學期第一次程式檢定 Scoreboard

Time

2017/09/29 18:00:00 2017/09/29 23:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11566 Tree distance
11568 Minesweeper
11572 Prime
11578 Base
11579 The Blocks Problem

11566 - Tree distance   

Description

Calculate the distance between two nodes.

Input

For each case, the first line contains a positive integer N (1 <= N <= 1000), denoting the number of node in the tree (labeled from 1 to N). The second line contains exactly N numbers. The first number denotes the parent of node 1, and the second number denotes the parent of node 2 ..., etc. The root will be labeled as -1.
For example, sample input

3

-1 1 1

node 1 is root.

The parent of node 2 is node 1.

The parent of node 3 is node 1.

 

Then follows multiple lines of query (query < 10000). Each line contains two positive integers A and B. The query is terminated by two zeros.

Do not assume it is a binary tree.

Output

For each case a line, print the case number first, then output the distance between A and B for each query. Each answer should be separated by a single space.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11568 - Minesweeper   

Description

 The problem is about minesweeper. Given an N*N matrix A whose elements are either 0 or 1. Output the another N*N matrix B. Every element in B is the sum of the adjacency “8” elements in the same location in A. If an element is on the boundary, the adjacency elements may not be “8”.

Input

The input includes multiple test cases. In each test case, the first line contains one integer N. The next N lines follow. Every line contains N elements which are either 1 or 0.

1 <= N <=100

Output

Output N lines. Every line contains N integers. Every two numbers are separated by single space.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11572 - Prime   

Description

Output the number of primes between two given integer a and b.

Input

The first line of input contains a positive integer t (t<=1000), which indicates the numbers of test cases in the input. In the next t line, each line contains two positive integers a, b(1 <= a <= b <= 10000), indicating the range between a and b.

Output

Output the number of primes in the range between a and b (including a and b).

Sample Input  Download

Sample Output  Download

Tags




Discuss




11578 - Base   

Description

Given a decimal integer n and a base k, translate n to the corresponding k-based number.

Input

The first line contains an integer t (1 <= t <= 20), which indicates the number of test cases in the input. Each test case is given in a line, containing two integers n and k (n <= 10000000, k<=9).

Output

Output the number in base k.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11579 - The Blocks Problem   

Description

Problem description
The problem is to parse a series of commands that instruct a robot arm in how to manipulate blocks lying on a flat table. Initially there are n blocks on the table (numbered from 0 to n-1) with block bi adjacent to block bi+1 for all 0 <= i < n-1 as shown in the figure below:


Figure 1. Initial Blocks World
The valid commands for the robot arm that manipulates blocks are:
move a onto b
where a and b are block numbers, put block a onto block b after returning any blocks that are stacked on top of blocks a and b to their initial positions.
move a over b
where a and b are block numbers, put block a onto the top of the stack containing block b, if there are other blocks, stacked on top of block a or block b . return them to their initial position, after returning any blocks that are stacked on top of block a to their initial positions.
pile a onto b
where a and b are block numbers, moves the pile of blocks consisting of block a, and any blocks that are stacked above block a, onto block b. All blocks on top of block b are moved to their initial positions prior to the pile taking place. The blocks stacked above block a retain their order when moved.
pile a over b
where a and b are block numbers, puts the pile of blocks consisting of block a, and any blocks that are stacked above block a, onto the top of the stack containing block b. The blocks stacked above block a retain their original order when moved.
quit
terminates manipulations in the block world.
Any command in which a = b or in which a and b are in the same stack of blocks is an illegal command. All illegal commands should be ignored and should have no affect on the configuration of blocks.

Input

The input begins with an integer n on a line by itself representing the number of blocks in the block world. You may assume that 0 < n < 25.
The number of blocks is followed by a sequence of block commands, one command per line. Your program should process all commands until the quit command is encountered.
You may assume that all commands will be of the form specified above. There will be no syntactically incorrect commands.

Output

The output should consist of the final state of the blocks world. Each original block position numbered i ( 0 <= i < n where n is the number of blocks) should appear followed immediately by a colon. If there is at least a block on it, the colon must be followed by one space, followed by a list of blocks that appear stacked in that position with each block number separated from other block numbers by a space. Don't put any trailing spaces on a line.
There should be one line of output for each block position (i.e., n lines of output where n is the integer on the first line of input).

Sample Input  Download

Sample Output  Download

Tags




Discuss