Problem A - Wheel of Fortune: Input
Problem A - Wheel of Fortune: Input
Problem A - Wheel of Fortune: Input
A - the number of types of gifts give out to the customers. In the previous example, A = 2.
B - the sum of square of how many times a gift is chosen. In the previous example, gift
#0 was selected once, gift #1 has never been selected, gift #2 was selected 3 times. Thus,
B = 12 + 02 + 32 = 10.
Given N and M, your task is to calculate the expected value of A and the expected value of B.
Input
The first line of input is the number of tests T (1 T 10,000). The following T tests, each will
consists of 2 integers N and M. (1 N, M 106)
Output
For each test case in the input, print out 2 numbers the expected value of A and the expected
value of B with exactly 2 digits after decimal point.
Sample
Sample input
3
12
21
33
Page 1 of 11
Explanation
For the first case, the only possible result is team 1 beat both team 2 and team 3, team 2 draw
team 3.
For the second case, there are 2 possible results:
Team 4 loses all other teams, team 1 beats team 2, team 2 beats team 3, team 3 beats
team 1.
Team 4 loses all other teams, team 1 beats team 3, team 3 beats team 2, team 2 beats
team 1.
Page 2 of 11
Page 3 of 11
Page 4 of 11
Page 5 of 11
Input
Input starts with an integer T, denoting the number of test cases.
Each case starts with a line containing an integer N (1 N 105) denoting the number of
operations.
Each of the next N lines starts with a character ('A', 'B', 'C' or 'S'), which indicates the
type of operation. Character 'A', 'B' or 'S' will be followed by two integers, s and t in the
same line. Character 'C' is followed by three integers, s, t and x. It's assumed that, 1 s
t 250,000 and -105 x 105. The meanings of these integers are explained above.
Output
For each case, print the case number first. Then for each operation 'S', print the result of query
in a line.
Sample
Sample input
2
5
A16
B35
S16
C 6 10 -2
S16
1
S 1 10
Page 6 of 11
Page 7 of 11
Problem H Cyclic
Smith is very good at mathematics. He loves interesting features of numbers. And one day, he
found a very special type of numbers called "cyclic number".
A cyclic number is a n-digits integer which, when multiplied by any integer from 1 to n, results
in a cycle of the digits of the original number.
The most widely known is 142857. This is as illustrated by the following explanation:
142857 1 = 142857
142857 2 = 285714
142857 3 = 428571
142857 4 = 571428
142857 5 = 714285
142857 6 = 857142
Write a program determining whether or not numbers are cyclic. The input file is a list of
integers from 2 to 60 digits in length. Note that for cyclic numbers, leading zeros are important.
So, preceding zeros should not be removed, they are considered part of the number and count in
determining n. Thus, 01 is a two-digit number, distinct from 1 which is a one-digit number.
Input
Each line contains an integer number.
Output
For each input integer, write a line in the output indicating whether or not it is cyclic.
Sample
Sample input
142857
142856
142858
01
0588235294117647
Page 8 of 11
Problem I Assign!
There are N students numbered from 0 to N-1. For each student i, we knowH[i] means that
student i hates student H[i]. We have K distinct classes. In how many ways can students be
assigned into those classes such that no student in any class hates any others in the same class?
Input
The first line of input is the number of test cases T. Each of them contains 2 lines.
The first line of each test case contains 2 integers N (2 N 100) and K (2 K 100).
The second line of each test case contains N integers, the i th integer (0-based) denoting
the value H[i] (0 H[i] <N; H[i] != i).
Output
For each testcase, output the number of ways modulo 1,000,000,007.
Sample
Sample input
3
33
120
43
1200
32
120
Page 9 of 11
Problem J Vacation
John is an engineer. On this summer, he has an intention to pay a visit to many places in his
country. The country contains total N cities numbered from 1 to N. There are M bidirectional
roads connecting these cities. Each of these roads connects 2 cities and cost an amount of time
to go between 2 connected cities.
All of these cities are very beautiful. After considerations, John chose Q cities to visit. John lives
in city 1. He does not have much time for the vacation, so he would like to minimize the amount
of time travelling on roads. He will start his journey from home, visiting Q cities, and then come
back home. Please help John!
Input
The first line contains the number of test cases T. For each of test cases:
The first line contains 3 integers N (1 N 5,000), M (1 M 100,000), Q (1 Q
10).
The second line contains Q integers, which are the cities John will visit.
Each of the next M lines contains 3 integers A, B, C, which indicates that there is a road
connecting city A and city B, and it takes C time units to travel. (1 A, B N; 0 < C
1,000,000).
Output
For each case, write a line in the output indicating the minimum amount of time John must
travel on roads. If there is no way to visit all Q cities, print -1.
Sample
Sample input
1
582
32
329
347
416
453
2 5 10
327
146
217
Page 10 of 11
To annoy Hieu the most, Thinh wants to choose as many boxes as possible to wrap the present.
Can you determine the maximal number of boxes Thinh could use?
Input
The first line is the number of tests T. Then T tests follow.
The first line of a test is R (R 100), followed by R lines, each contains 2 integers ai, bi
(1 ai, bi 100).
The next is C (C 100), followed by C lines, each contains a positive integer ri (1 ri
100).
Output
For each test, print the maximal number of boxes Thinh could use.
Sample
Sample input
1
3
22
23
34
1
3
Page 11 of 11