555 - 102學年上學期第三次程式檢定 Scoreboard

Time

2013/12/26 18:35:00 2013/12/27 00:35:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
9420 Count the Leaves
9424 K Characters
9428 Subset Sum
9432 Set Intersection
9436 GCD and LCM

9420 - Count the Leaves   

Description

Given a tree, count the number of leaves in this tree. Each node has unique integer identification (ID), but all IDs may not be consecutive.

Input

There are multiple test cases. Each test case begins with an integer N (1 <= N <=1000). In the following N lines, each line has two integer a and b (1 <= a,b <= 1000), indicating node a is node b’s parent. The next line contains an integer R, which represents the root of the Tree. You can assume that all the nodes will be on the same tree. The input is terminated by N = 0.

Output

Print the number of the leaves for each test case.

Hint: All leaves have no children!

Sample Input  Download

Sample Output  Download

Tags

10402HW10



Discuss




9424 - K Characters   

Description

Given a string, output all different possible set of K characters in the string.  And sort them in the dictionary order.  For example, if K=2 and the given string is ‘CDBABBD’, output

AB
AC
AD
BB
BC
BD
CD
DD

 

Hint : DFS

Input

The first line of input contains a positive integer t (t <= 30), which indicates the number of test cases.  For each case, there are one strings and a positive integer Kin a line. The length of the string is less than 100 and strings contain only 'A'-'K'; The number K, less than or equal to 10, indicates the length of substrings.

Case 1: 1 <= K <= 3
Case 2: 1 <= K <= 5
Case 3: 1 <= K <= 10
Case 4: 1 <= K <= 10

Output

 For each test case, output all different possible set of K characters in the string.  And sort them in the dictionary order, one substring per line.  Print a blank line after each test case.

Sample Input  Download

Sample Output  Download

Tags




Discuss




9428 - Subset Sum   

Description

Given N numbers. You need to separate them A and B such that is minimum.
Note that a set can be empty.

Input

Each case starts with a positive integer N, then the next line contains exactly N integers n1~nN.

A test case of N = 0 indicates the end of input, and should not be processed.

For case 1, 1<=N<=3, 0<=ni<=100
For case 2, 1<=N<=5, 0<=ni<=10000
For case 3, 1<=N<=10, 0<=ni<=100000
For case 4, 1<=N<=20, -1000000<=ni<=1000000

Hint: Try to enumerate all possible combinitions.

Output

Output one line per case that contains an integer denoting the minimum value of .

Sample Input  Download

Sample Output  Download

Tags




Discuss




9432 - Set Intersection   

Description

Given two sets of numbers, output their intersection set.

Hint: sorting

Input

There are multiple test cases. Each case contains four lines. The first line begins with an integer N. The second line contains N integers, representing the numbers in the first set. The third line has one integer M, and the fourth line contains M integers, represent the numbers in the second set. All the numbers are 32 bit signed integers. The input is terminated if N = 0.

For case 1, 1 <= N, M <= 103
For case 2, 1 <= N, M <= 104
For case 3, 1 <= N, M <= 105
For case 4, 1 <= N, M <= 106

Output

For each test case, print the intersection of the two sets. Output them in ascending order. If the intersection of the two sets is an empty set, print “empty” (without quotes).

Sample Input  Download

Sample Output  Download

Tags




Discuss




9436 - GCD and LCM   

Description

Given three positive integers x, y, and z, compute their greatest common divisor (GCD) and least common multiple (LCM). The GCD of two or more numbers is the largest positive integer that can divide the numbers without a reminder. The LCM of two or more numbers is the smallest positive integer that can be divided by all of the numbers without a reminder.

hint : gcd(a,b,c) = gcd(gcd(a,b),c)

Input

The first line contains a positive integer N (N<=1000), which indicates the number of test cases in the input. In the next N lines, each line contains three positive integers x, y, and z, each of which is not greater than 10^6.

case 1 : numbers <= 10^2

case 2 : numbers <= 10^3

case 3 : numbers <= 10^5

case 4 : numbers <= 10^6

Output

For each case, output the GCD and LCM of x, y, and z in a line.

Sample Input  Download

Sample Output  Download

Tags




Discuss