diff --git a/.gitignore b/.gitignore index 1086f56..bee8a64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -html __pycache__ diff --git a/html/a1001.html b/html/a1001.html new file mode 100644 index 0000000..5c17487 --- /dev/null +++ b/html/a1001.html @@ -0,0 +1,16 @@ + + +

1001. A+B Format (20)

+
+

Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

+

Input

+

Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

+

Output

+

For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

+Sample Input
+-1000000 9
+
+Sample Output
+-999,991
+
+

\ No newline at end of file diff --git a/html/a1002.html b/html/a1002.html new file mode 100644 index 0000000..245ff3a --- /dev/null +++ b/html/a1002.html @@ -0,0 +1,19 @@ + + +

1002. A+B for Polynomials (25)

+
+

This time, you are supposed to find A+B where A and B are two polynomials.

+

Input

+

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: +K N1 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10,0 <= NK < ... < N2 < N1 <=1000. +

+

Output

+

For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

+Sample Input
+2 1 2.4 0 3.2
+2 2 1.5 1 0.5
+
+Sample Output
+3 2 1.5 1 2.9 0 3.2
+
+

\ No newline at end of file diff --git a/html/a1003.html b/html/a1003.html new file mode 100644 index 0000000..cd028c0 --- /dev/null +++ b/html/a1003.html @@ -0,0 +1,26 @@ + + +

1003. Emergency (25)

+
+

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

+

Input

+

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. +It is guaranteed that there exists at least one path from C1 to C2. +

+

Output

+

For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather.
+All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

+Sample Input
+5 6 0 2
+1 2 1 5 3
+0 1 1
+0 2 2
+0 3 1
+1 2 1
+2 4 1
+3 4 1
+
+Sample Output
+2 4
+
+

\ No newline at end of file diff --git a/html/a1004.html b/html/a1004.html new file mode 100644 index 0000000..a66037b --- /dev/null +++ b/html/a1004.html @@ -0,0 +1,22 @@ + + +

1004. Counting Leaves (30)

+
+ A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.

+

Input

+

Each input file contains one test case. Each case starts with a line containing 0 < N < 100, the number of nodes in a tree, and M (< N), the number of non-leaf nodes. Then M lines follow, each in the format:

+
+ID K ID[1] ID[2] ... ID[K]
+
+where ID is a two-digit number representing a given non-leaf node, K is the number of its children, followed by a sequence of two-digit ID's of its children. For the sake of simplicity, let us fix the root ID to be 01.

+

Output

+

For each test case, you are supposed to count those family members who have no child for every seniority level starting from the root. The numbers must be printed in a line, separated by a space, and there must be no extra space at the end of each line.

+

The sample case represents a tree with only 2 nodes, where 01 is the root and 02 is its only child. Hence on the root 01 level, there is 0 leaf node; and on the next level, there is 1 leaf node. Then we should output "0 1" in a line.

+Sample Input
+2 1
+01 1 02
+
+Sample Output
+0 1
+
+
\ No newline at end of file diff --git a/html/a1005.html b/html/a1005.html new file mode 100644 index 0000000..761d0e7 --- /dev/null +++ b/html/a1005.html @@ -0,0 +1,23 @@ + + +

1005. Spell It Right (20)

+
+

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English. +

+

+Input Specification: +

+

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100). +

+

+Output Specification: +

+

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line. +

+Sample Input:
+12345
+
+Sample Output:
+one five
+
+
\ No newline at end of file diff --git a/html/a1006.html b/html/a1006.html new file mode 100644 index 0000000..147ee74 --- /dev/null +++ b/html/a1006.html @@ -0,0 +1,30 @@ + + +

1006. Sign In and Sign Out (25)

+
+

At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day. +

+

+Input Specification: +

+

Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:

+
+ID_number Sign_in_time Sign_out_time
+
+

where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters. +

+

+Output Specification: +

+

For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.

+

Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.

+Sample Input:
+3
+CS301111 15:30:28 17:00:10
+SC3021234 08:00:00 11:25:25
+CS301133 21:45:00 21:58:40
+
+Sample Output:
+SC3021234 CS301133
+
+
\ No newline at end of file diff --git a/html/a1007.html b/html/a1007.html new file mode 100644 index 0000000..6ee25f5 --- /dev/null +++ b/html/a1007.html @@ -0,0 +1,25 @@ + + +

1007. Maximum Subsequence Sum (25)

+
+

Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.

+

Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence. +

+

+Input Specification: +

+

Each input file contains one test case. Each case occupies two lines. The first line contains a positive integer K (<= 10000). The second line contains K numbers, separated by a space. +

+

+Output Specification: +

+

For each test case, output in one line the largest sum, together with the first and the last numbers of the maximum subsequence. The numbers must be separated by one space, but there must be no extra space at the end of a line. In case that the maximum subsequence is not unique, output the one with the smallest indices i and j (as shown by the sample case). If all the K numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence. +

+Sample Input:
+10
+-10 1 2 3 4 -5 -23 3 7 -21
+
+Sample Output:
+10 1 4
+
+
\ No newline at end of file diff --git a/html/a1008.html b/html/a1008.html new file mode 100644 index 0000000..60e5ff9 --- /dev/null +++ b/html/a1008.html @@ -0,0 +1,21 @@ + + +

1008. Elevator (20)

+
+

The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

+

For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

+

+Input Specification: +

+

Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.

+

+Output Specification: +

+

For each test case, print the total time on a single line.

+Sample Input:
+3 2 3 1
+
+Sample Output:
+41
+
+
\ No newline at end of file diff --git a/html/a1009.html b/html/a1009.html new file mode 100644 index 0000000..8527ee9 --- /dev/null +++ b/html/a1009.html @@ -0,0 +1,23 @@ + + +

1009. Product of Polynomials (25)

+
+

This time, you are supposed to find A*B where A and B are two polynomials.

+

+Input Specification: +

+

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: +K N1 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10, 0 <= NK < ... < N2 < N1 <=1000. +

+

+Output Specification: +

+

For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.

+Sample Input
+2 1 2.4 0 3.2
+2 2 1.5 1 0.5
+
+Sample Output
+3 3 3.6 2 6.0 1 1.6
+
+

\ No newline at end of file diff --git a/html/a1010.html b/html/a1010.html new file mode 100644 index 0000000..fc10df8 --- /dev/null +++ b/html/a1010.html @@ -0,0 +1,32 @@ + + +

1010. Radix (25)

+
+

Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is "yes", if 6 is a decimal number and 110 is a binary number. +

+

+Now for any pair of positive integers N1 and N2, your task is to find the radix of one number while that of the other is given.

+

+Input Specification: +

+

Each input file contains one test case. Each case occupies a line which contains 4 positive integers:
+N1 N2 tag radix
+Here N1 and N2 each has no more than 10 digits. A digit is less than its radix and is chosen from the set {0-9, a-z} where 0-9 represent the decimal numbers 0-9, and a-z represent the decimal numbers 10-35. The last number "radix" is the radix of N1 if "tag" is 1, or of N2 if "tag" is 2.

+

+Output Specification: +

+

For each test case, print in one line the radix of the other number so that the equation N1 = N2 is true. If the equation is impossible, print "Impossible". If the solution is not unique, output the smallest possible radix. +

+Sample Input 1:
+6 110 1 10
+
+Sample Output 1:
+2
+
+Sample Input 2:
+1 ab 1 2
+
+Sample Output 2:
+Impossible
+
+
\ No newline at end of file diff --git a/html/a1011.html b/html/a1011.html new file mode 100644 index 0000000..53d8332 --- /dev/null +++ b/html/a1011.html @@ -0,0 +1,27 @@ + + +

1011. World Cup Betting (20)

+
+

With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.

+

Chinese Football Lottery provided a "Triple Winning" game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results -- namely W for win, T for tie, and L for lose. There was an odd assigned to each result. The winner's odd would be the product of the three odds times 65%.

+

For example, 3 games' odds are given as the following:

+
+ W    T    L
+1.1  2.5  1.7
+1.2  3.0  1.6
+4.1  1.2  1.1
+
+

To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd game, and T for the 1st game. If each bet takes 2 yuans, then the maximum profit would be (4.1*3.0*2.5*65%-1)*2 = 37.98 yuans (accurate up to 2 decimal places).

+

Input

+

Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to W, T and L.

+

Output

+

For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.

+Sample Input
+1.1 2.5 1.7
+1.2 3.0 1.6
+4.1 1.2 1.1
+
+Sample Output
+T T W 37.98
+
+
\ No newline at end of file diff --git a/html/a1012.html b/html/a1012.html new file mode 100644 index 0000000..76a3982 --- /dev/null +++ b/html/a1012.html @@ -0,0 +1,43 @@ + + +

1012. The Best Rank (25)

+
+

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.

+

For example, The grades of C, M, E and A - Average of 4 students are given as the following:

+
+StudentID  C  M  E  A
+310101     98 85 88 90
+310102     70 95 88 84
+310103     82 87 94 88
+310104     91 91 91 91
+
+

Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

+

Input

+

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

+

Output

+

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

+

The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

+

If a student is not on the grading list, simply output "N/A".

+Sample Input
+5 6
+310101 98 85 88
+310102 70 95 88
+310103 82 87 94
+310104 91 91 91
+310105 85 90 90
+310101
+310102
+310103
+310104
+310105
+999999
+
+Sample Output
+1 C
+1 M
+1 E
+1 A
+3 A
+N/A
+
+
\ No newline at end of file diff --git a/html/a1013.html b/html/a1013.html new file mode 100644 index 0000000..8095bde --- /dev/null +++ b/html/a1013.html @@ -0,0 +1,22 @@ + + +

1013. Battle Over Cities (25)

+
+

It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep the rest of the cities connected. Given the map of cities which have all the remaining highways marked, you are supposed to tell the number of highways need to be repaired, quickly.

+

For example, if we have 3 cities and 2 highways connecting city1-city2 and city1-city3. Then if city1 is occupied by the enemy, we must have 1 highway repaired, that is the highway city2-city3.

+

Input

+

Each input file contains one test case. Each case starts with a line containing 3 numbers N (&lt1000;), M and K, which are the total number of cities, the number of remaining highways, and the number of cities to be checked, respectively. Then M lines follow, each describes a highway by 2 integers, which are the numbers of the cities the highway connects. The cities are numbered from 1 to N. Finally there is a line containing K numbers, which represent the cities we concern.

+

Output

+

For each of the K cities, output in a line the number of highways need to be repaired if that city is lost.

+Sample Input
+3 2 3
+1 2
+1 3
+1 2 3
+
+Sample Output
+1
+0
+0
+
+
\ No newline at end of file diff --git a/html/a1014.html b/html/a1014.html new file mode 100644 index 0000000..05f9e3d --- /dev/null +++ b/html/a1014.html @@ -0,0 +1,33 @@ + + +

1014. Waiting in Line (30)

+
+

Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:

+ +

Now given the processing time of each customer, you are supposed to tell the exact time at which a customer has his/her business done.

+

For example, suppose that a bank has 2 windows and each window may have 2 customers waiting inside the yellow line. There are 5 customers waiting with transactions taking 1, 2, 6, 4 and 3 minutes, respectively. At 08:00 in the morning, customer1 is served at window1 while customer2 is served at window2. Customer3 will wait in front of window1 and customer4 will wait in front of window2. Customer5 will wait behind the yellow line.

+

At 08:01, customer1 is done and customer5 enters the line in front of window1 since that line seems shorter now. Customer2 will leave at 08:02, customer4 at 08:06, customer3 at 08:07, and finally customer5 at 08:10.

+

Input

+

Each input file contains one test case. Each case starts with a line containing 4 positive integers: N (<=20, number of windows), M (<=10, the maximum capacity of each line inside the yellow line), K (<=1000, number of customers), and Q (<=1000, number of customer queries).

+

The next line contains K positive integers, which are the processing time of the K customers.

+

The last line contains Q positive integers, which represent the customers who are asking about the time they can have their transactions done. The customers are numbered from 1 to K.

+

Output

+

For each of the Q customers, print in one line the time at which his/her transaction is finished, in the format HH:MM where HH is in [08, 17] and MM is in [00, 59]. Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output "Sorry" instead.

+Sample Input
+2 2 7 5
+1 2 6 4 3 534 2
+3 4 5 6 7
+
+Sample Output
+08:07
+08:06
+08:10
+17:00
+Sorry
+
+
\ No newline at end of file diff --git a/html/a1015.html b/html/a1015.html new file mode 100644 index 0000000..9c68af8 --- /dev/null +++ b/html/a1015.html @@ -0,0 +1,28 @@ + + +

1015. Reversible Primes (20)

+
+

A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime. +

+

Now given any two positive integers N (< 105) and D (1 < D <= 10), you are supposed to tell if N is a reversible prime with radix D. + +

+Input Specification: +

+

The input file consists of several test cases. Each case occupies a line which contains two integers N and D. The input is finished by a negative N.

+

+Output Specification: +

+

For each test case, print in one line "Yes" if N is a reversible prime with radix D, or "No" if not.

+Sample Input:
+73 10
+23 2
+23 10
+-2
+
+Sample Output:
+Yes
+Yes
+No
+
+

\ No newline at end of file diff --git a/html/a1016.html b/html/a1016.html new file mode 100644 index 0000000..b66b526 --- /dev/null +++ b/html/a1016.html @@ -0,0 +1,47 @@ + + +

1016. Phone Bills (25)

+
+

A long-distance telephone company charges its customers by the following rules:

+

+Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records.

+

+Input Specification: +

+

Each input file contains one test case. Each case has two parts: the rate structure, and the phone call records.

+

The rate structure consists of a line with 24 non-negative integers denoting the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and so on for each hour in the day.

+

The next line contains a positive number N (<= 1000), followed by N lines of records. Each phone call record consists of the name of the customer (string of up to 20 characters without space), the time and date (mm:dd:hh:mm), and the word "on-line" or "off-line".

+

For each test case, all dates will be within a single month. Each "on-line" record is paired with the chronologically next record for the same customer provided it is an "off-line" record. Any "on-line" records that are not paired with an "off-line" record are ignored, as are "off-line" records not paired with an "on-line" record. It is guaranteed that at least one call is well paired in the input. You may assume that no two records for the same customer have the same time. Times are recorded using a 24-hour clock.

+

+Output Specification: +

+

For each test case, you must print a phone bill for each customer.

+

Bills must be printed in alphabetical order of customers' names. +For each customer, first print in a line the name of the customer and the month of the bill in the format shown by the sample. Then for each time period of a call, print in one line the beginning and ending time and date (dd:hh:mm), the lasting time (in minute) and the charge of the call. The calls must be listed in chronological order. Finally, print the total charge for the month in the format shown by the sample.

+Sample Input:
+10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
+10
+CYLL 01:01:06:01 on-line
+CYLL 01:28:16:05 off-line
+CYJJ 01:01:07:00 off-line
+CYLL 01:01:08:03 off-line
+CYJJ 01:01:05:59 on-line
+aaa 01:01:01:03 on-line
+aaa 01:02:00:01 on-line
+CYLL 01:28:15:41 on-line
+aaa 01:05:02:24 on-line
+aaa 01:04:23:59 off-line
+
+Sample Output:
+CYJJ 01
+01:05:59 01:07:00 61 $12.10
+Total amount: $12.10
+CYLL 01
+01:06:01 01:08:03 122 $24.40
+28:15:41 28:16:05 24 $3.85
+Total amount: $28.25
+aaa 01
+02:00:01 04:23:59 4318 $638.80
+Total amount: $638.80
+
+
\ No newline at end of file diff --git a/html/a1017.html b/html/a1017.html new file mode 100644 index 0000000..758f644 --- /dev/null +++ b/html/a1017.html @@ -0,0 +1,29 @@ + + +

1017. Queueing at Bank (25)

+
+

Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.

+

Now given the arriving time T and the processing time P of each customer, you are supposed to tell the average waiting time of all the customers.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=10000) - the total number of customers, and K (<=100) - the number of windows. Then N lines follow, each contains 2 times: HH:MM:SS - the arriving time, and P - the processing time in minutes of a customer. Here HH is in the range [00, 23], MM and SS are both in [00, 59]. It is assumed that no two customers arrives at the same time.

+

Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.

+

+Output Specification: +

+

For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.

+Sample Input:
+7 3
+07:55:00 16
+17:00:01 2
+07:59:59 15
+08:01:00 60
+08:00:00 30
+08:00:02 2
+08:03:00 10
+
+Sample Output:
+8.2
+
+
\ No newline at end of file diff --git a/html/a1018.html b/html/a1018.html new file mode 100644 index 0000000..e072dfc --- /dev/null +++ b/html/a1018.html @@ -0,0 +1,34 @@ + + +

1018. Public Bike Management (30)

+
+

There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city.

+

The Public Bike Management Center (PBMC) keeps monitoring the real-time capacity of all the stations. A station is said to be in perfect condition if it is exactly half-full. If a station is full or empty, PBMC will collect or send bikes to adjust the condition of that station to perfect. And more, all the stations on the way will be adjusted as well.

+

When a problem station is reported, PBMC will always choose the shortest path to reach that station. If there are more than one shortest path, the one that requires the least number of bikes sent from PBMC will be chosen.

+

Figure 1
+

Figure 1 illustrates an example. The stations are represented by vertices and the roads correspond to the edges. The number on an edge is the time taken to reach one end station from another. The number written inside a vertex S is the current number of bikes stored at S. Given that the maximum capacity of each station is 10. To solve the problem at S3, we have 2 different shortest paths:

+

1. PBMC -> S1 -> S3. In this case, 4 bikes must be sent from PBMC, because we can collect 1 bike from S1 and then take 5 bikes to S3, so that both stations will be in perfect conditions.

+

2. PBMC -> S2 -> S3. This path requires the same time as path 1, but only 3 bikes sent from PBMC and hence is the one that will be chosen.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 4 numbers: Cmax (<= 100), always an even number, is the maximum capacity of each station; N (<= 500), the total number of stations; Sp, the index of the problem station (the stations are numbered from 1 to N, and PBMC is represented by the vertex 0); and M, the number of roads. The second line contains N non-negative numbers Ci (i=1,...N) where each Ci is the current number of bikes at Si respectively. Then M lines follow, each contains 3 numbers: Si, Sj, and Tij which describe the time Tij taken to move betwen stations Si and Sj. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print your results in one line. First output the number of bikes that PBMC must send. Then after one space, output the path in the format: 0-&gtS;1-&gt...-;&gtS;p. Finally after another space, output the number of bikes that we must take back to PBMC after the condition of Sp is adjusted to perfect.

+

Note that if such a path is not unique, output the one that requires minimum number of bikes that we must take back to PBMC. The judge's data guarantee that such a path is unique. +

+Sample Input:
+10 3 3 5
+6 7 0
+0 1 1
+0 2 1
+0 3 3
+1 3 1
+2 3 1
+
+Sample Output:
+3 0-&gt2-;&gt3; 0
+
+
\ No newline at end of file diff --git a/html/a1019.html b/html/a1019.html new file mode 100644 index 0000000..2825587 --- /dev/null +++ b/html/a1019.html @@ -0,0 +1,35 @@ + + +

1019. General Palindromic Number (20)

+
+

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. +

+

Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N > 0 in base b >= 2, where it is written in standard notation with k+1 digits ai as the sum of (aibi) for i from 0 to k. Here, as usual, 0 <= ai < b for all i and ak is non-zero. Then N is palindromic if and only if ai = ak-i for all i. Zero is written 0 in any base and is also palindromic by definition. +

+

Given any non-negative decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b. +

+

+Input Specification: +

+

Each input file contains one test case. Each case consists of two non-negative numbers N and b, where 0 <= N <= 109 is the decimal number and 2 <= b <= 109 is the base. The numbers are separated by a space. +

+

+Output Specification: +

+

For each test case, first print in one line "Yes" if N is a palindromic number in base b, or "No" if not. Then in the next line, print N as the number in base b in the form "ak ak-1 ... a0". Notice that there must be no extra space at the end of output. +

+Sample Input 1:
+27 2
+
+Sample Output 1:
+Yes
+1 1 0 1 1
+
+Sample Input 2:
+121 5
+
+Sample Output 2:
+No
+4 4 1
+
+
\ No newline at end of file diff --git a/html/a1020.html b/html/a1020.html new file mode 100644 index 0000000..b1a1373 --- /dev/null +++ b/html/a1020.html @@ -0,0 +1,22 @@ + + +

1020. Tree Traversals (25)

+
+

Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line gives a positive integer N (<=30), the total number of nodes in the binary tree. The second line gives the postorder sequence and the third line gives the inorder sequence. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print in one line the level order traversal sequence of the corresponding binary tree. All the numbers in a line must be separated by exactly one space, and there must be no extra space at the end of the line.

+Sample Input:
+7
+2 3 1 5 7 6 4
+1 2 3 4 5 6 7
+
+Sample Output:
+4 1 6 3 5 7 2
+
+
\ No newline at end of file diff --git a/html/a1021.html b/html/a1021.html new file mode 100644 index 0000000..4239fa3 --- /dev/null +++ b/html/a1021.html @@ -0,0 +1,36 @@ + + +

1021. Deepest Root (25)

+
+

A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains a positive integer N (<=10000) which is the number of nodes, and hence the nodes are numbered from 1 to N. Then N-1 lines follow, each describes an edge by given the two adjacent nodes' numbers.

+

+Output Specification: +

+

For each test case, print each of the deepest roots in a line. If such a root is not unique, print them in increasing order of their numbers. In case that the given graph is not a tree, print "Error: K components" where K is the number of connected components in the graph.

+Sample Input 1:
+5
+1 2
+1 3
+1 4
+2 5
+
+Sample Output 1:
+3
+4
+5
+
+Sample Input 2:
+5
+1 3
+1 4
+2 5
+3 4
+
+Sample Output 2:
+Error: 2 components
+
+
\ No newline at end of file diff --git a/html/a1022.html b/html/a1022.html new file mode 100644 index 0000000..e7114a1 --- /dev/null +++ b/html/a1022.html @@ -0,0 +1,78 @@ + + +

1022. Digital Library (30)

+
+

A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number as its ID. Given any query from a reader, you are supposed to output the resulting books, sorted in increasing order of their ID's.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains a positive integer N (<=10000) which is the total number of books. Then N blocks follow, each contains the information of a book in 6 lines:

+ +

It is assumed that each book belongs to one author only, and contains no more than 5 key words; there are no more than 1000 distinct key words in total; and there are no more than 1000 distinct publishers.

+

After the book information, there is a line containing a positive integer M (<=1000) which is the number of user's search queries. Then M lines follow, each in one of the formats shown below:

+ +

+Output Specification: +

+

For each query, first print the original query in a line, then output the resulting book ID's in increasing order, each occupying a line. If no book is found, print "Not Found" instead.

+Sample Input:
+3
+1111111
+The Testing Book
+Yue Chen
+test code debug sort keywords
+ZUCS Print
+2011
+3333333
+Another Testing Book
+Yue Chen
+test code sort keywords
+ZUCS Print2
+2012
+2222222
+The Testing Book
+CYLL
+keywords debug book
+ZUCS Print2
+2011
+6
+1: The Testing Book
+2: Yue Chen
+3: keywords
+4: ZUCS Print
+5: 2011
+3: blablabla
+
+Sample Output:
+1: The Testing Book
+1111111
+2222222
+2: Yue Chen
+1111111
+3333333
+3: keywords
+1111111
+2222222
+3333333
+4: ZUCS Print
+1111111
+5: 2011
+1111111
+2222222
+3: blablabla
+Not Found
+
+
\ No newline at end of file diff --git a/html/a1023.html b/html/a1023.html new file mode 100644 index 0000000..548a753 --- /dev/null +++ b/html/a1023.html @@ -0,0 +1,23 @@ + + +

1023. Have Fun with Numbers (20)

+
+

Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again! +

+

Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

+

+Input Specification: +

+

Each input file contains one test case. Each case contains one positive integer with no more than 20 digits.

+

+Output Specification: +

+

For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.

+Sample Input:
+1234567899
+
+Sample Output:
+Yes
+2469135798
+
+
\ No newline at end of file diff --git a/html/a1024.html b/html/a1024.html new file mode 100644 index 0000000..4bf94ce --- /dev/null +++ b/html/a1024.html @@ -0,0 +1,33 @@ + + +

1024. Palindromic Number (25)

+
+

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. +

+

Non-palindromic numbers can be paired with palindromic ones via a series of operations. First, the non-palindromic number is reversed and the result is added to the original number. If the result is not a palindromic number, this is repeated until it gives a palindromic number. For example, if we start from 67, we can obtain a palindromic number in 2 steps: 67 + 76 = 143, and 143 + 341 = 484. +

+

Given any positive integer N, you are supposed to find its paired palindromic number and the number of steps taken to find it. +

+

+Input Specification: +

+

Each input file contains one test case. Each case consists of two positive numbers N and K, where N (<= 1010) is the initial numer and K (<= 100) is the maximum number of steps. The numbers are separated by a space.

+

+Output Specification: +

+

For each test case, output two numbers, one in each line. The first number is the paired palindromic number of N, and the second number is the number of steps taken to find the palindromic number. If the palindromic number is not found after K steps, just output the number obtained at the Kth step and K instead.

+Sample Input 1:
+67 3
+
+Sample Output 1:
+484
+2
+
+Sample Input 2:
+69 3
+
+Sample Output 2:
+1353
+3
+
+
\ No newline at end of file diff --git a/html/a1025.html b/html/a1025.html new file mode 100644 index 0000000..f295dd0 --- /dev/null +++ b/html/a1025.html @@ -0,0 +1,42 @@ + + +

1025. PAT Ranking (25)

+
+

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains a positive number N (<=100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (<=300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

+

registration_number final_rank location_number local_rank

+

The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

+Sample Input:
+2
+5
+1234567890001 95
+1234567890005 100
+1234567890003 95
+1234567890002 77
+1234567890004 85
+4
+1234567890013 65
+1234567890011 25
+1234567890014 100
+1234567890012 85
+
+Sample Output:
+9
+1234567890005 1 1 1
+1234567890014 1 2 1
+1234567890001 3 1 2
+1234567890003 3 1 2
+1234567890004 5 1 4
+1234567890012 5 2 2
+1234567890002 7 1 5
+1234567890013 8 2 3
+1234567890011 9 2 4
+
+
\ No newline at end of file diff --git a/html/a1026.html b/html/a1026.html new file mode 100644 index 0000000..4b14f8a --- /dev/null +++ b/html/a1026.html @@ -0,0 +1,41 @@ + + +

1026. Table Tennis (30)

+
+

A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open when they arrive, they will be assigned to the available table with the smallest number. If all the tables are occupied, they will have to wait in a queue. It is assumed that every pair of players can play for at most 2 hours.

+

Your job is to count for everyone in queue their waiting time, and for each table the number of players it has served for the day.

+

One thing that makes this procedure a bit complicated is that the club reserves some tables for their VIP members. When a VIP table is open, the first VIP pair in the queue will have the priviledge to take it. However, if there is no VIP in the queue, the next pair of players can take it. On the other hand, if when it is the turn of a VIP pair, yet no VIP table is available, they can be assigned as any ordinary players.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains an integer N (<=10000) - the total number of pairs of players. Then N lines follow, each contains 2 times and a VIP tag: HH:MM:SS - the arriving time, P - the playing time in minutes of a pair of players, and tag - which is 1 if they hold a VIP card, or 0 if not. It is guaranteed that the arriving time is between 08:00:00 and 21:00:00 while the club is open. It is assumed that no two customers arrives at the same time. Following the players' info, there are 2 positive integers: K (<=100) - the number of tables, and M (< K) - the number of VIP tables. The last line contains M table numbers.

+

+Output Specification: +

+

For each test case, first print the arriving time, serving time and the waiting time for each pair of players in the format shown by the sample. Then print in a line the number of players served by each table. Notice that the output must be listed in chronological order of the serving time. The waiting time must be rounded up to an integer minute(s). If one cannot get a table before the closing time, their information must NOT be printed.

+Sample Input:
+9
+20:52:00 10 0
+08:00:00 20 0
+08:02:00 30 0
+20:51:00 10 0
+08:10:00 5 0
+08:12:00 10 1
+20:50:00 10 0
+08:01:30 15 1
+20:53:00 10 1
+3 1
+2
+
+Sample Output:
+08:00:00 08:00:00 0
+08:01:30 08:01:30 0
+08:02:00 08:02:00 0
+08:12:00 08:16:30 5
+08:10:00 08:20:00 10
+20:50:00 20:50:00 0
+20:51:00 20:51:00 0
+20:52:00 20:52:00 0
+3 3 2
+
+
\ No newline at end of file diff --git a/html/a1027.html b/html/a1027.html new file mode 100644 index 0000000..e075e4a --- /dev/null +++ b/html/a1027.html @@ -0,0 +1,17 @@ + + +

1027. Colors in Mars (20)

+
+

People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the last 2 digits for Blue. The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values.

+

Input

+

Each input file contains one test case which occupies a line containing the three decimal color values. +

+

Output

+

For each test case you should output the Mars RGB value in the following format: first output "#", then followed by a 6-digit number where all the English characters must be upper-cased. If a single color is only 1-digit long, you must print a "0" to the left.

+Sample Input
+15 43 71
+
+Sample Output
+#123456
+
+

\ No newline at end of file diff --git a/html/a1028.html b/html/a1028.html new file mode 100644 index 0000000..3d67805 --- /dev/null +++ b/html/a1028.html @@ -0,0 +1,47 @@ + + +

1028. List Sorting (25)

+
+

Excel can sort records according to any column. Now you are supposed to imitate this function.

+

Input

+

Each input file contains one test case. For each case, the first line contains two integers N (<=100000) and C, where N is the number of records and C is the column that you are supposed to sort the records with. Then N lines follow, each contains a record of a student. A student's record consists of his or her distinct ID (a 6-digit number), name (a string with no more than 8 characters without space), and grade (an integer between 0 and 100, inclusive).

+

Output

+

For each test case, output the sorting result in N lines. That is, if C = 1 then the records must be sorted in increasing order according to ID's; if C = 2 then the records must be sorted in non-decreasing order according to names; and if C = 3 then the records must be sorted in non-decreasing order according to grades. If there are several students who have the same name or grade, they must be sorted according to their ID's in increasing order.

+Sample Input 1
+3 1
+000007 James 85
+000010 Amy 90
+000001 Zoe 60
+
+Sample Output 1
+000001 Zoe 60
+000007 James 85
+000010 Amy 90
+
+Sample Input 2
+4 2
+000007 James 85
+000010 Amy 90
+000001 Zoe 60
+000002 James 98
+
+Sample Output 2
+000010 Amy 90
+000002 James 98
+000007 James 85
+000001 Zoe 60
+
+Sample Input 3
+4 3
+000007 James 85
+000010 Amy 90
+000001 Zoe 60
+000002 James 90
+
+Sample Output 3
+000001 Zoe 60
+000007 James 85
+000002 James 90
+000010 Amy 90
+
+
\ No newline at end of file diff --git a/html/a1029.html b/html/a1029.html new file mode 100644 index 0000000..b793c76 --- /dev/null +++ b/html/a1029.html @@ -0,0 +1,18 @@ + + +

1029. Median (25)

+
+

Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The median of two sequences is defined to be the median of the nondecreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.

+

Given two increasing sequences of integers, you are asked to find their median.

+

Input

+

Each input file contains one test case. Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (<=1000000) is the size of that sequence. Then N integers follow, separated by a space. It is guaranteed that all the integers are in the range of long int.

+

Output

+

For each test case you should output the median of the two given sequences in a line.

+Sample Input
+4 11 12 13 14
+5 9 10 15 16 17
+
+Sample Output
+13
+
+
\ No newline at end of file diff --git a/html/a1030.html b/html/a1030.html new file mode 100644 index 0000000..cb3bfcf --- /dev/null +++ b/html/a1030.html @@ -0,0 +1,31 @@ + + +

1030. Travel Plan (30)

+
+

A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting city and the destination. If such a shortest path is not unique, you are supposed to output the one with the minimum cost, which is guaranteed to be unique. +

+

+Input Specification: +

+

Each input file contains one test case. Each case starts with a line containing 4 positive integers N, M, S, and D, where N (<=500) is the number of cities (and hence the cities are numbered from 0 to N-1); M is the number of highways; S and D are the starting and the destination cities, respectively. Then M lines follow, each provides the information of a highway, in the format:

+

City1 City2 Distance Cost +

+

where the numbers are all integers no more than 500, and are separated by a space. +

+

+Output Specification: +

+

For each test case, print in one line the cities along the shortest path from the starting point to the destination, followed by the total distance and the total cost of the path. The numbers must be separated by a space and there must be no extra space at the end of output. +

+Sample Input
+4 5 0 3
+0 1 1 20
+1 3 2 30
+0 3 4 10
+0 2 2 20
+2 3 1 20
+
+Sample Output
+0 2 3 3 40
+
+
\ No newline at end of file diff --git a/html/a1031.html b/html/a1031.html new file mode 100644 index 0000000..d8d4df9 --- /dev/null +++ b/html/a1031.html @@ -0,0 +1,30 @@ + + +

1031. Hello World for U (20)

+
+

Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. For example, "helloworld" can be printed as:

+h  d
+e  l
+l  r
+lowo
+
+ +That is, the characters must be printed in the original order, starting top-down from the left vertical line with n1 characters, then left to right along the bottom line with n2 characters, and finally bottom-up along the vertical line with n3 characters. And more, we would like U to be as squared as possible -- that is, it must be satisfied that n1 = n3 = max { k| k <= n2 for all 3 <= n2 <= N } with n1 + n2 + n3 - 2 = N.

+

+Input Specification: +

+

Each input file contains one test case. Each case contains one string with no less than 5 and no more than 80 characters in a line. The string contains no white space.

+

+Output Specification: +

+

For each test case, print the input string in the shape of U as specified in the description.

+Sample Input:
+helloworld!
+
+Sample Output:
+h   !
+e   d
+l   l
+lowor
+
+
\ No newline at end of file diff --git a/html/a1032.html b/html/a1032.html new file mode 100644 index 0000000..0783f8c --- /dev/null +++ b/html/a1032.html @@ -0,0 +1,45 @@ + + +

1032. Sharing (25)

+
+

To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example, "loading" and "being" are stored as showed in Figure 1.

+

Figure 1
+

You are supposed to find the starting position of the common suffix (e.g. the position of "i" in Figure 1).

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains two addresses of nodes and a positive N (<= 105), where the two addresses are the addresses of the first nodes of the two words, and N is the total number of nodes. The address of a node is a 5-digit positive integer, and NULL is represented by -1.

+

Then N lines follow, each describes a node in the format:

+

Address Data Next

+

where Address is the position of the node, Data is the letter contained by this node which is an English letter chosen from {a-z, A-Z}, and Next is the position of the next node.

+

+Output Specification: +

+

For each case, simply output the 5-digit starting position of the common suffix. If the two words have no common suffix, output "-1" instead. +

+Sample Input 1:
+11111 22222 9
+67890 i 00002
+00010 a 12345
+00003 g -1
+12345 D 67890
+00002 n 00003
+22222 B 23456
+11111 L 00001
+23456 e 67890
+00001 o 00010
+
+Sample Output 1:
+67890
+
+Sample Input 2:
+00001 00002 4
+00001 a 10001
+10001 s -1
+00002 a 10002
+10002 t -1
+
+Sample Output 2:
+-1
+
+
\ No newline at end of file diff --git a/html/a1033.html b/html/a1033.html new file mode 100644 index 0000000..45b1d23 --- /dev/null +++ b/html/a1033.html @@ -0,0 +1,36 @@ + + +

1033. To Fill or Not to Fill (25)

+
+

With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give different price. You are asked to carefully design the cheapest route to go.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 4 positive numbers: Cmax (<= 100), the maximum capacity of the tank; D (<=30000), the distance between Hangzhou and the destination city; Davg (<=20), the average distance per unit gas that the car can run; and N (<= 500), the total number of gas stations. Then N lines follow, each contains a pair of non-negative numbers: Pi, the unit gas price, and Di (<=D), the distance between this station and Hangzhou, for i=1,...N. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print the cheapest price in a line, accurate up to 2 decimal places. It is assumed that the tank is empty at the beginning. If it is impossible to reach the destination, print "The maximum travel distance = X" where X is the maximum possible distance the car can run, accurate up to 2 decimal places.

+Sample Input 1:
+50 1300 12 8
+6.00 1250
+7.00 600
+7.00 150
+7.10 0
+7.20 200
+7.50 400
+7.30 1000
+6.85 300
+
+Sample Output 1:
+749.17
+
+Sample Input 2:
+50 1300 12 2
+7.10 0
+7.00 600
+
+Sample Output 2:
+The maximum travel distance = 1200.00
+
+
\ No newline at end of file diff --git a/html/a1034.html b/html/a1034.html new file mode 100644 index 0000000..e983edf --- /dev/null +++ b/html/a1034.html @@ -0,0 +1,46 @@ + + +

1034. Head of a Gang (30)

+
+

One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length of all the phone calls made between the two persons. A "Gang" is a cluster of more than 2 persons who are related to each other with total relation weight being greater than a given threshold K. In each gang, the one with maximum total weight is the head. Now given a list of phone calls, you are supposed to find the gangs and the heads.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains two positive numbers N and K (both less than or equal to 1000), the number of phone calls and the weight threshold, respectively. Then N lines follow, each in the following format:

+

Name1 Name2 Time

+

where Name1 and Name2 are the names of people at the two ends of the call, and Time is the length of the call. A name is a string of three capital letters chosen from A-Z. A time length is a positive integer which is no more than 1000 minutes.

+

+Output Specification: +

+

For each test case, first print in a line the total number of gangs. Then for each gang, print in a line the name of the head and the total number of the members. It is guaranteed that the head is unique for each gang. The output must be sorted according to the alphabetical order of the names of the heads.

+Sample Input 1:
+8 59
+AAA BBB 10
+BBB AAA 20
+AAA CCC 40
+DDD EEE 5
+EEE DDD 70
+FFF GGG 30
+GGG HHH 20
+HHH FFF 10
+
+Sample Output 1:
+2
+AAA 3
+GGG 3
+
+Sample Input 2:
+8 70
+AAA BBB 10
+BBB AAA 20
+AAA CCC 40
+DDD EEE 5
+EEE DDD 70
+FFF GGG 30
+GGG HHH 20
+HHH FFF 10
+
+Sample Output 2:
+0
+
+
\ No newline at end of file diff --git a/html/a1035.html b/html/a1035.html new file mode 100644 index 0000000..85935a8 --- /dev/null +++ b/html/a1035.html @@ -0,0 +1,40 @@ + + +

1035. Password (20)

+
+

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

+

+Input Specification: +

+

Each input file contains one test case. Each case contains a positive integer N (<= 1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.

+

+Output Specification: +

+

For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line "There are N accounts and no account is modified" where N is the total number of accounts. However, if N is one, you must print "There is 1 account and no account is modified" instead.

+Sample Input 1:

+3
+Team000002 Rlsp0dfa
+Team000003 perfectpwd
+Team000001 R1spOdfa
+
+Sample Output 1:
+2
+Team000002 RLsp%dfa
+Team000001 R@spodfa
+
+Sample Input 2:
+1
+team110 abcdefg332
+
+Sample Output 2:
+There is 1 account and no account is modified
+
+Sample Input 3:
+2
+team110 abcdefg222
+team220 abcdefg333
+
+Sample Output 3:
+There are 2 accounts and no account is modified
+
+

\ No newline at end of file diff --git a/html/a1036.html b/html/a1036.html new file mode 100644 index 0000000..b2746fd --- /dev/null +++ b/html/a1036.html @@ -0,0 +1,34 @@ + + +

1036. Boys vs Girls (25)

+
+

This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.

+

+Input Specification: +

+

Each input file contains one test case. Each case contains a positive integer N, followed by N lines of student information. Each line contains a student's name, gender, ID and grade, separated by a space, where name and ID are strings of no more than 10 characters with no space, gender is either F (female) or M (male), and grade is an integer between 0 and 100. It is guaranteed that all the grades are distinct.

+

+Output Specification: +

+

For each test case, output in 3 lines. The first line gives the name and ID of the female student with the highest grade, and the second line gives that of the male student with the lowest grade. The third line gives the difference gradeF-gradeM. If one such kind of student is missing, output "Absent" in the corresponding line, and output "NA" in the third line instead.

+Sample Input 1:

+3
+Joe M Math990112 89
+Mike M CS991301 100
+Mary F EE990830 95
+
+Sample Output 1:
+Mary EE990830
+Joe Math990112
+6
+
+Sample Input 2:
+1
+Jean M AA980920 60
+
+Sample Output 2:
+Absent
+Jean AA980920
+NA
+
+

\ No newline at end of file diff --git a/html/a1037.html b/html/a1037.html new file mode 100644 index 0000000..33a3d42 --- /dev/null +++ b/html/a1037.html @@ -0,0 +1,25 @@ + + +

1037. Magic Coupon (25)

+
+

The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value of that product back! What is more, the shop also offers some bonus product for free. However, if you apply a coupon with a positive N to this bonus product, you will have to pay the shop N times the value of the bonus product... but hey, magically, they have some coupons with negative N's!

+

For example, given a set of coupons {1 2 4 -1}, and a set of product values {7 6 -2 -3} (in Mars dollars M$) where a negative value corresponds to a bonus product. You can apply coupon 3 (with N being 4) to product 1 (with value M$7) to get M$28 back; coupon 2 to product 2 to get M$12 back; and coupon 4 to product 4 to get M$3 back. On the other hand, if you apply coupon 3 to product 4, you will have to pay M$12 to the shop.

+

Each coupon and each product may be selected at most once. Your task is to get as much money back as possible.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains the number of coupons NC, followed by a line with NC coupon integers. Then the next line contains the number of products NP, followed by a line with NP product values. Here 1<= NC, NP <= 105, and it is guaranteed that all the numbers will not exceed 230.

+

+Output Specification: +

+

For each test case, simply print in a line the maximum amount of money you can get back.

+Sample Input:
+4
+1 2 4 -1
+4
+7 6 -2 -3
+
+Sample Output:
+43
+
+
\ No newline at end of file diff --git a/html/a1038.html b/html/a1038.html new file mode 100644 index 0000000..855aeb2 --- /dev/null +++ b/html/a1038.html @@ -0,0 +1,21 @@ + + +

1038. Recover the Smallest Number (30)

+
+

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different orders of combinations of these segments, and the smallest number is 0229-321-3214-32-87.

+

+Input Specification: +

+

Each input file contains one test case. Each case gives a positive integer N (<=10000) followed by N number segments. Each segment contains a non-negative integer of no more than 8 digits. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print the smallest number in one line. Do not output leading zeros. +

+Sample Input:
+5 32 321 3214 0229 87
+
+Sample Output:
+22932132143287
+
+
\ No newline at end of file diff --git a/html/a1039.html b/html/a1039.html new file mode 100644 index 0000000..7535ac0 --- /dev/null +++ b/html/a1039.html @@ -0,0 +1,42 @@ + + +

1039. Course List for Student (25)

+
+

Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 positive integers: N (<=40000), the number of students who look for their course lists, and K (<=2500), the total number of courses. Then the student name lists are given for the courses (numbered from 1 to K) in the following format: for each course i, first the course index i and the number of registered students Ni (<= 200) are given in a line. Then in the next line, Ni student names are given. A student name consists of 3 capital English letters plus a one-digit number. Finally the last line contains the N names of students who come for a query. All the names and numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print your results in N lines. Each line corresponds to one student, in the following format: first print the student's name, then the total number of registered courses of that student, and finally the indices of the courses in increasing order. The query results must be printed in the same order as input. All the data in a line must be separated by a space, with no extra space at the end of the line. +

+Sample Input:
+11 5
+4 7
+BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
+1 4
+ANN0 BOB5 JAY9 LOR6
+2 7
+ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR6
+3 1
+BOB5
+5 9
+AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
+ZOE1 ANN0 BOB5 JOE4 JAY9 FRA8 DON2 AMY7 KAT3 LOR6 NON9
+
+Sample Output:
+ZOE1 2 4 5
+ANN0 3 1 2 5
+BOB5 5 1 2 3 4 5
+JOE4 1 2
+JAY9 4 1 2 4 5
+FRA8 3 2 4 5
+DON2 2 4 5
+AMY7 1 5
+KAT3 3 2 4 5
+LOR6 4 1 2 4 5
+NON9 0
+
+
\ No newline at end of file diff --git a/html/a1040.html b/html/a1040.html new file mode 100644 index 0000000..3fbaa71 --- /dev/null +++ b/html/a1040.html @@ -0,0 +1,20 @@ + + +

1040. Longest Symmetric String (25)

+
+

Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given "Is PAT&TAP; symmetric?", the longest symmetric sub-string is "s PAT&TAP; s", hence you must output 11.

+

+Input Specification: +

+

Each input file contains one test case which gives a non-empty string of length no more than 1000.

+

+Output Specification: +

+

For each test case, simply print the maximum length in a line.

+Sample Input:
+Is PAT&TAP; symmetric?
+
+Sample Output:
+11
+
+
\ No newline at end of file diff --git a/html/a1041.html b/html/a1041.html new file mode 100644 index 0000000..03ce6a0 --- /dev/null +++ b/html/a1041.html @@ -0,0 +1,27 @@ + + +

1041. Be Unique (20)

+
+

Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 104]. The first one who bets on a unique number wins. For example, if there are 7 people betting on 5 31 5 88 67 88 17, then the second one who bets on 31 wins.

+

+Input Specification: +

+

Each input file contains one test case. Each case contains a line which begins with a positive integer N (<=105) and then followed by N bets. The numbers are separated by a space.

+

+Output Specification: +

+

For each test case, print the winning number in a line. If there is no winner, print "None" instead. +

+Sample Input 1:
+7 5 31 5 88 67 88 17
+
+Sample Output 1:
+31
+
+Sample Input 2:
+5 888 666 666 888 888
+
+Sample Output 2:
+None
+
+
\ No newline at end of file diff --git a/html/a1042.html b/html/a1042.html new file mode 100644 index 0000000..dba42e5 --- /dev/null +++ b/html/a1042.html @@ -0,0 +1,28 @@ + + +

1042. Shuffling Machine (20)

+
+

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines. Your task is to simulate a shuffling machine.

+

The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order:

+

S1, S2, ..., S13, +H1, H2, ..., H13, +C1, C2, ..., C13, +D1, D2, ..., D13, +J1, J2

+

where "S" stands for "Spade", "H" for "Heart", "C" for "Club", "D" for "Diamond", and "J" for "Joker". A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains a positive integer K (<= 20) which is the number of repeat times. Then the next line contains the given order. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print the shuffling results in one line. All the cards are separated by a space, and there must be no extra space at the end of the line.

+Sample Input:
+2
+36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47
+
+Sample Output:
+S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5
+
+
\ No newline at end of file diff --git a/html/a1043.html b/html/a1043.html new file mode 100644 index 0000000..28016ed --- /dev/null +++ b/html/a1043.html @@ -0,0 +1,44 @@ + + +

1043. Is It a Binary Search Tree (25)

+
+

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:

+ +

If we swap the left and right subtrees of every node, then the resulting tree is called the Mirror Image of a BST.

+

Now given a sequence of integer keys, you are supposed to tell if it is the preorder traversal sequence of a BST or the mirror image of a BST.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains a positive integer N (<=1000). Then N integer keys are given in the next line. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, first print in a line "YES" if the sequence is the preorder traversal sequence of a BST or the mirror image of a BST, or "NO" if not. Then if the answer is "YES", print in the next line the postorder traversal sequence of that tree. All the numbers in a line must be separated by a space, and there must be no extra space at the end of the line. +

+Sample Input 1:
+7
+8 6 5 7 10 8 11
+
+Sample Output 1:
+YES
+5 7 6 8 11 10 8
+
+Sample Input 2:
+7
+8 10 11 8 6 7 5
+
+Sample Output 2:
+YES
+11 8 10 7 5 6 8
+
+Sample Input 3:
+7
+8 6 8 5 10 9 11
+
+Sample Output 3:
+NO
+
+
\ No newline at end of file diff --git a/html/a1044.html b/html/a1044.html new file mode 100644 index 0000000..ea7448a --- /dev/null +++ b/html/a1044.html @@ -0,0 +1,41 @@ + + +

1044. Shopping in Mars (25)

+
+

Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diamonds are taken off the chain one by one. Once a diamond is off the chain, it cannot be taken back. For example, if we have a chain of 8 diamonds with values M$3, 2, 1, 5, 4, 6, 8, 7, and we must pay M$15. We may have 3 options:

+

+1. Cut the chain between 4 and 6, and take off the diamonds from the position 1 to 5 (with values 3+2+1+5+4=15).
+2. Cut before 5 or after 6, and take off the diamonds from the position 4 to 6 (with values 5+4+6=15).
+3. Cut before 8, and take off the diamonds from the position 7 to 8 (with values 8+7=15).
+

+

Now given the chain of diamond values and the amount that a customer has to pay, you are supposed to list all the paying options for the customer.

+

If it is impossible to pay the exact amount, you must suggest solutions with minimum lost.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=105), the total number of diamonds on the chain, and M (<=108), the amount that the customer has to pay. Then the next line contains N positive numbers D1 ... DN (Di<=103 for all i=1, ..., N) which are the values of the diamonds. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print "i-j" in a line for each pair of i <= j such that Di + ... + Dj = M. Note that if there are more than one solution, all the solutions must be printed in increasing order of i.

+

If there is no solution, output "i-j" for pairs of i <= j such that Di + ... + Dj > M with (Di + ... + Dj - M) minimized. Again all the solutions must be printed in increasing order of i.

+

It is guaranteed that the total value of diamonds is sufficient to pay the given amount.

+Sample Input 1:
+16 15
+3 2 1 5 4 6 8 7 16 10 15 11 9 12 14 13
+
+Sample Output 1:
+1-5
+4-6
+7-8
+11-11
+
+Sample Input 2:
+5 13
+2 4 5 7 9
+
+Sample Output 2:
+2-4
+4-5
+
+
\ No newline at end of file diff --git a/html/a1045.html b/html/a1045.html new file mode 100644 index 0000000..04f6a2d --- /dev/null +++ b/html/a1045.html @@ -0,0 +1,24 @@ + + +

1045. Favorite Color Stripe (30)

+
+

Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to form her favorite color stripe.

+

It is said that a normal human eye can distinguish about less than 200 different colors, so Eva's favorite colors are limited. However the original stripe could be very long, and Eva would like to have the remaining favorite stripe with the maximum length. So she needs your help to find her the best result.

+

Note that the solution might not be unique, but you only have to tell her the maximum length. For example, given a stripe of colors {2 2 4 1 5 5 6 3 1 1 5 6}. If Eva's favorite colors are given in her favorite order as {2 3 1 5 6}, then she has 4 possible best solutions {2 2 1 1 1 5 6}, {2 2 1 5 5 5 6}, {2 2 1 5 5 6 6}, and {2 2 3 1 1 5 6}.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains a positive integer N (<=200) which is the total number of colors involved (and hence the colors are numbered from 1 to N). Then the next line starts with a positive integer M (<=200) followed by M Eva's favorite color numbers given in her favorite order. Finally the third line starts with a positive integer L (<=10000) which is the length of the given stripe, followed by L colors on the stripe. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, simply print in a line the maximum length of Eva's favorite stripe.

+Sample Input:
+6
+5 2 3 1 5 6
+12 2 2 4 1 5 5 6 3 1 1 5 6
+
+Sample Output:
+7
+
+
\ No newline at end of file diff --git a/html/a1046.html b/html/a1046.html new file mode 100644 index 0000000..4dee4a5 --- /dev/null +++ b/html/a1046.html @@ -0,0 +1,26 @@ + + +

1046. Shortest Distance (20)

+
+

The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains an integer N (in [3, 105]), followed by N integer distances D1 D2 ... DN, where Di is the distance between the i-th and the (i+1)-st exits, and DN is between the N-th and the 1st exits. All the numbers in a line are separated by a space. The second line gives a positive integer M (<=104), with M lines follow, each contains a pair of exit numbers, provided that the exits are numbered from 1 to N. It is guaranteed that the total round trip distance is no more than 107.

+

+Output Specification: +

+

For each test case, print your results in M lines, each contains the shortest distance between the corresponding given pair of exits.

+Sample Input:
+5 1 2 4 14 9
+3
+1 3
+2 5
+4 1
+
+Sample Output:
+3
+10
+7
+
+
\ No newline at end of file diff --git a/html/a1047.html b/html/a1047.html new file mode 100644 index 0000000..fa234d3 --- /dev/null +++ b/html/a1047.html @@ -0,0 +1,62 @@ + + +

1047. Student List for Course (25)

+
+

Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=40000), the total number of students, and K (<=2500), the total number of courses. Then N lines follow, each contains a student's name (3 capital English letters plus a one-digit number), a positive number C (<=20) which is the number of courses that this student has registered, and then followed by C course numbers. For the sake of simplicity, the courses are numbered from 1 to K.

+

+Output Specification: +

+

For each test case, print the student name lists of all the courses in increasing order of the course numbers. For each course, first print in one line the course number and the number of registered students, separated by a space. Then output the students' names in alphabetical order. Each name occupies a line.

+Sample Input:
+10 5
+ZOE1 2 4 5
+ANN0 3 5 2 1
+BOB5 5 3 4 2 1 5
+JOE4 1 2
+JAY9 4 1 2 5 4
+FRA8 3 4 2 5
+DON2 2 4 5
+AMY7 1 5
+KAT3 3 5 4 2
+LOR6 4 2 4 1 5
+
+Sample Output:
+1 4
+ANN0
+BOB5
+JAY9
+LOR6
+2 7
+ANN0
+BOB5
+FRA8
+JAY9
+JOE4
+KAT3
+LOR6
+3 1
+BOB5
+4 7
+BOB5
+DON2
+FRA8
+JAY9
+KAT3
+LOR6
+ZOE1
+5 9
+AMY7
+ANN0
+BOB5
+DON2
+FRA8
+JAY9
+KAT3
+LOR6
+ZOE1
+
+
\ No newline at end of file diff --git a/html/a1048.html b/html/a1048.html new file mode 100644 index 0000000..30d4096 --- /dev/null +++ b/html/a1048.html @@ -0,0 +1,28 @@ + + +

1048. Find Coins (25)

+
+

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requirement of the payment: for each bill, she could only use exactly two coins to pay the exact amount. Since she has as many as 105 coins with her, she definitely needs your help. You are supposed to tell her, for any given amount of money, whether or not she can find two coins to pay for it.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 positive numbers: N (<=105, the total number of coins) and M(<=103, the amount of money Eva has to pay). The second line contains N face values of the coins, which are all positive numbers no more than 500. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print in one line the two face values V1 and V2 (separated by a space) such that V1 + V2 = M and V1 <= V2. If such a solution is not unique, output the one with the smallest V1. If there is no solution, output "No Solution" instead.

+Sample Input 1:
+8 15
+1 2 8 7 2 4 11 15
+
+Sample Output 1:
+4 11
+
+Sample Input 2:
+7 14
+1 8 7 2 4 11 15
+
+Sample Output 2:
+No Solution
+
+
\ No newline at end of file diff --git a/html/a1049.html b/html/a1049.html new file mode 100644 index 0000000..bfe6935 --- /dev/null +++ b/html/a1049.html @@ -0,0 +1,20 @@ + + +

1049. Counting Ones (30)

+
+

The task is simple: given any positive integer N, you are supposed to count the total number of 1's in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1's in 1, 10, 11, and 12.

+

+Input Specification: +

+

Each input file contains one test case which gives the positive N (<=230).

+

+Output Specification: +

+

For each test case, print the number of 1's in one line.

+Sample Input:
+12
+
+Sample Output:
+5
+
+
\ No newline at end of file diff --git a/html/a1050.html b/html/a1050.html new file mode 100644 index 0000000..8cd1e3d --- /dev/null +++ b/html/a1050.html @@ -0,0 +1,21 @@ + + +

1050. String Subtraction (20)

+
+

Given two strings S1 and S2, S = S1 - S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1 - S2 for any given strings. However, it might not be that simple to do it fast.

+

+Input Specification: +

+

Each input file contains one test case. Each case consists of two lines which gives S1 and S2, respectively. The string lengths of both strings are no more than 104. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.

+

+Output Specification: +

+

For each test case, print S1 - S2 in one line.

+Sample Input:
+They are students.
+aeiou
+
+Sample Output:
+Thy r stdnts.
+
+
\ No newline at end of file diff --git a/html/a1051.html b/html/a1051.html new file mode 100644 index 0000000..08a5e38 --- /dev/null +++ b/html/a1051.html @@ -0,0 +1,29 @@ + + +

1051. Pop Sequence (25)

+
+

Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obtain 1, 2, 3, 4, 5, 6, 7 from the stack, but not 3, 2, 1, 7, 5, 6, 4.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 3 numbers (all no more than 1000): M (the maximum capacity of the stack), N (the length of push sequence), and K (the number of pop sequences to be checked). Then K lines follow, each contains a pop sequence of N numbers. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each pop sequence, print in one line "YES" if it is indeed a possible pop sequence of the stack, or "NO" if not.

+Sample Input:
+5 7 5
+1 2 3 4 5 6 7
+3 2 1 7 5 6 4
+7 6 5 4 3 2 1
+5 6 4 3 7 2 1
+1 7 6 5 4 3 2
+
+Sample Output:
+YES
+NO
+NO
+YES
+NO
+
+
\ No newline at end of file diff --git a/html/a1052.html b/html/a1052.html new file mode 100644 index 0000000..ff15b9c --- /dev/null +++ b/html/a1052.html @@ -0,0 +1,33 @@ + + +

1052. Linked List Sorting (25)

+
+

A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, you are supposed to sort the structures according to their key values in increasing order.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains a positive N (< 105) and an address of the head node, where N is the total number of nodes in memory and the address of a node is a 5-digit positive integer. NULL is represented by -1.

+

Then N lines follow, each describes a node in the format:

+

Address Key Next

+

where Address is the address of the node in memory, Key is an integer in [-105, 105], and Next is the address of the next node. It is guaranteed that all the keys are distinct and there is no cycle in the linked list starting from the head node.

+

+Output Specification: +

+

For each test case, the output format is the same as that of the input, where N is the total number of nodes in the list and all the nodes must be sorted order.

+Sample Input:
+5 00001
+11111 100 -1
+00001 0 22222
+33333 100000 11111
+12345 -1 33333
+22222 1000 12345
+
+Sample Output:
+5 12345
+12345 -1 00001
+00001 0 11111
+11111 100 22222
+22222 1000 33333
+33333 100000 -1
+
+
\ No newline at end of file diff --git a/html/a1053.html b/html/a1053.html new file mode 100644 index 0000000..372df7b --- /dev/null +++ b/html/a1053.html @@ -0,0 +1,42 @@ + + +

1053. Path of Equal Weight (30)

+
+

Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R to any leaf node L.

+

Now given any weighted tree, you are supposed to find all the paths with their weights equal to a given number. For example, let's consider the tree showed in Figure 1: for each node, the upper number is the node ID which is a two-digit number, and the lower number is the weight of that node. Suppose that the given number is 24, then there exists 4 different paths which have the same given weight: {10 5 2 7}, {10 4 10}, {10 3 3 6 2} and {10 3 3 6 2}, which correspond to the red edges in Figure 1. +

+

Figure 1
+

+Input Specification: +

+

Each input file contains one test case. Each case starts with a line containing 0 < N <= 100, the number of nodes in a tree, M (< N), the number of non-leaf nodes, and 0 < S < 230, the given weight number. The next line contains N positive numbers where Wi (&lt1000;) corresponds to the tree node Ti. Then M lines follow, each in the format:

+
+ID K ID[1] ID[2] ... ID[K]
+
+

where ID is a two-digit number representing a given non-leaf node, K is the number of its children, followed by a sequence of two-digit ID's of its children. For the sake of simplicity, let us fix the root ID to be 00.

+

+Output Specification: +

+

For each test case, print all the paths with weight S in non-increasing order. Each path occupies a line with printed weights from the root to the leaf in order. All the numbers must be separated by a space with no extra space at the end of the line. +

+

Note: sequence {A1, A2, ..., An} is said to be greater than sequence {B1, B2, ..., Bm} if there exists 1 <= k < min{n, m} such that Ai = Bi for i=1, ... k, and Ak+1 > Bk+1.

+Sample Input:
+20 9 24
+10 2 4 3 5 10 2 18 9 7 2 2 1 3 12 1 8 6 2 2
+00 4 01 02 03 04
+02 1 05
+04 2 06 07
+03 3 11 12 13
+06 1 09
+07 2 08 10
+16 1 15
+13 3 14 16 17
+17 2 18 19
+
+Sample Output:
+10 5 2 7
+10 4 10
+10 3 3 6 2
+10 3 3 6 2
+
+
\ No newline at end of file diff --git a/html/a1054.html b/html/a1054.html new file mode 100644 index 0000000..90bd3a4 --- /dev/null +++ b/html/a1054.html @@ -0,0 +1,23 @@ + + +

1054. The Dominant Color (20)

+
+

Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes more than half of the total area. Now given an image of resolution M by N (for example, 800x600), you are supposed to point out the strictly dominant color.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 positive numbers: M (<=800) and N (<=600) which are the resolutions of the image. Then N lines follow, each contains M digital colors in the range [0, 224). It is guaranteed that the strictly dominant color exists for each input image. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, simply print the dominant color in a line.

+Sample Input:
+5 3
+0 0 255 16777215 24
+24 24 0 0 24
+24 0 24 24 24
+
+Sample Output:
+24
+
+
\ No newline at end of file diff --git a/html/a1055.html b/html/a1055.html new file mode 100644 index 0000000..268e02a --- /dev/null +++ b/html/a1055.html @@ -0,0 +1,55 @@ + + +

1055. The World's Richest (25)

+
+

Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range of ages. That is, given the net worths of N people, you must find the M richest people in a given range of their ages.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 positive integers: N (<=105) - the total number of people, and K (<=103) - the number of queries. Then N lines follow, each contains the name (string of no more than 8 characters without space), age (integer in (0, 200]), and the net worth (integer in [-106, 106]) of a person. Finally there are K lines of queries, each contains three positive integers: M (<= 100) - the maximum number of outputs, and [Amin, Amax] which are the range of ages. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each query, first print in a line "Case #X:" where X is the query number starting from 1. Then output the M richest people with their ages in the range [Amin, Amax]. Each person's information occupies a line, in the format

+Name Age Net_Worth
+
+The outputs must be in non-increasing order of the net worths. In case there are equal worths, it must be in non-decreasing order of the ages. If both worths and ages are the same, then the output must be in non-decreasing alphabetical order of the names. It is guaranteed that there is no two persons share all the same of the three pieces of information. In case no one is found, output "None". +

+Sample Input:
+12 4
+Zoe_Bill 35 2333
+Bob_Volk 24 5888
+Anny_Cin 95 999999
+Williams 30 -22
+Cindy 76 76000
+Alice 18 88888
+Joe_Mike 32 3222
+Michael 5 300000
+Rosemary 40 5888
+Dobby 24 5888
+Billy 24 5888
+Nobody 5 0
+4 15 45
+4 30 35
+4 5 95
+1 45 50
+
+Sample Output:
+Case #1:
+Alice 18 88888
+Billy 24 5888
+Bob_Volk 24 5888
+Dobby 24 5888
+Case #2:
+Joe_Mike 32 3222
+Zoe_Bill 35 2333
+Williams 30 -22
+Case #3:
+Anny_Cin 95 999999
+Michael 5 300000
+Alice 18 88888
+Cindy 76 76000
+Case #4:
+None
+
+
\ No newline at end of file diff --git a/html/a1056.html b/html/a1056.html new file mode 100644 index 0000000..6afe5f6 --- /dev/null +++ b/html/a1056.html @@ -0,0 +1,25 @@ + + +

1056. Mice and Rice (25)

+
+

Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice as possible in order to become a FatMouse.

+

First the playing order is randomly decided for NP programmers. Then every NG programmers are grouped in a match. The fattest mouse in a group wins and enters the next turn. All the losers in this turn are ranked the same. Every NG winners are then grouped in the next match until a final winner is determined.

+

For the sake of simplicity, assume that the weight of each mouse is fixed once the programmer submits his/her code. Given the weights of all the mice and the initial playing order, you are supposed to output the ranks for the programmers.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 positive integers: NP and NG (<= 1000), the number of programmers and the maximum number of mice in a group, respectively. If there are less than NG mice at the end of the player's list, then all the mice left will be put into the last group. The second line contains NP distinct non-negative numbers Wi (i=0,...NP-1) where each Wi is the weight of the i-th mouse respectively. The third line gives the initial playing order which is a permutation of 0,...NP-1 (assume that the programmers are numbered from 0 to NP-1). All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print the final ranks in a line. The i-th number is the rank of the i-th programmer, and all the numbers must be separated by a space, with no extra space at the end of the line. +

+Sample Input:
+11 3
+25 18 0 46 37 3 19 22 57 56 10
+6 0 8 7 10 5 9 1 4 2 3
+
+Sample Output:
+5 5 5 2 5 5 5 3 1 3 5
+
+
\ No newline at end of file diff --git a/html/a1057.html b/html/a1057.html new file mode 100644 index 0000000..9316379 --- /dev/null +++ b/html/a1057.html @@ -0,0 +1,55 @@ + + +

1057. Stack (30)

+
+

Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and Pop (deleting the top element). Now you are supposed to implement a stack with an extra operation: PeekMedian -- return the median value of all the elements in the stack. With N elements, the median value is defined to be the (N/2)-th smallest element if N is even, or ((N+1)/2)-th if N is odd.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains a positive integer N (<= 105). Then N lines follow, each contains a command in one of the following 3 formats:

+ +Push key
+Pop
+PeekMedian

+ +where key is a positive integer no more than 105.

+

+Output Specification: +

+

For each Push command, insert key into the stack and output nothing. For each Pop or PeekMedian command, print in a line the corresponding returned value. If the command is invalid, print "Invalid" instead. +

+Sample Input:
+17
+Pop
+PeekMedian
+Push 3
+PeekMedian
+Push 2
+PeekMedian
+Push 1
+PeekMedian
+Pop
+Pop
+Push 5
+Push 4
+PeekMedian
+Pop
+Pop
+Pop
+Pop
+
+Sample Output:
+Invalid
+Invalid
+3
+2
+2
+1
+2
+4
+4
+5
+3
+Invalid
+
+
\ No newline at end of file diff --git a/html/a1058.html b/html/a1058.html new file mode 100644 index 0000000..bb3b580 --- /dev/null +++ b/html/a1058.html @@ -0,0 +1,21 @@ + + +

1058. A+B in Hogwarts (20)

+
+

If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it's easy enough." Your job is to write a program to compute A+B where A and B are given in the standard form of "Galleon.Sickle.Knut" (Galleon is an integer in [0, 107], Sickle is an integer in [0, 17), and Knut is an integer in [0, 29)).

+

+Input Specification: +

+

Each input file contains one test case which occupies a line with A and B in the standard form, separated by one space. +

+

+Output Specification: +

+

For each test case you should output the sum of A and B in one line, with the same format as the input.

+Sample Input:
+3.2.1 10.16.27
+
+Sample Output:
+14.1.28
+
+
\ No newline at end of file diff --git a/html/a1059.html b/html/a1059.html new file mode 100644 index 0000000..5348e37 --- /dev/null +++ b/html/a1059.html @@ -0,0 +1,20 @@ + + +

1059. Prime Factors (25)

+
+

Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1 * p2^k2 *…*pm^km.

+

+Input Specification: +

+

Each input file contains one test case which gives a positive integer N in the range of long int.

+

+Output Specification: +

+

Factor N in the format N = p1^k1 * p2^k2 *…*pm^km, where pi's are prime factors of N in increasing order, and the exponent ki is the number of pi -- hence when there is only one pi, ki is 1 and must NOT be printed out.

+Sample Input:
+97532468
+
+Sample Output:
+97532468=2^2*11*17*101*1291
+
+
\ No newline at end of file diff --git a/html/a1060.html b/html/a1060.html new file mode 100644 index 0000000..406ef30 --- /dev/null +++ b/html/a1060.html @@ -0,0 +1,28 @@ + + +

1060. Are They Equal (25)

+
+

If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123*105 with simple chopping. Now given the number of significant digits on a machine and two float numbers, you are supposed to tell if they are treated equal in that machine. +

+

+Input Specification: +

+

Each input file contains one test case which gives three numbers N, A and B, where N (<100) is the number of significant digits, and A and B are the two float numbers to be compared. Each float number is non-negative, no greater than 10100, and that its total digit number is less than 100.

+

+Output Specification: +

+

For each test case, print in a line "YES" if the two numbers are treated equal, and then the number in the standard form "0.d1...dN*10^k" (d1>0 unless the number is 0); or "NO" if they are not treated equal, and then the two numbers in their standard form. All the terms must be separated by a space, with no extra space at the end of a line.

+

Note: Simple chopping is assumed without rounding.

+Sample Input 1:
+3 12300 12358.9
+
+Sample Output 1:
+YES 0.123*10^5
+
+Sample Input 2:
+3 120 128
+
+Sample Output 2:
+NO 0.120*10^3 0.128*10^3
+
+
\ No newline at end of file diff --git a/html/a1061.html b/html/a1061.html new file mode 100644 index 0000000..fceb9e0 --- /dev/null +++ b/html/a1061.html @@ -0,0 +1,27 @@ + + +

1061. Dating (20)

+
+

Sherlock Holmes received a note with some strange strings: "Let's date! +3485djDkxh4hhGE +2984akDfkkkkggEdsb +s&hgsfdk; +d&Hyscvnm;". It took him only a minute to figure out that those strange strings are actually referring to the coded time "Thursday 14:04" -- since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter 'D', representing the 4th day in a week; the second common character is the 5th capital letter 'E', representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is 's' at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time.

+

+Input Specification: +

+

Each input file contains one test case. Each case gives 4 non-empty strings of no more than 60 characters without white space in 4 lines.

+

+Output Specification: +

+

For each test case, print the decoded time in one line, in the format "DAY HH:MM", where "DAY" is a 3-character abbreviation for the days in a week -- that is, "MON" for Monday, "TUE" for Tuesday, "WED" for Wednesday, "THU" for Thursday, "FRI" for Friday, "SAT" for Saturday, and "SUN" for Sunday. It is guaranteed that the result is unique for each case.

+Sample Input:
+3485djDkxh4hhGE 
+2984akDfkkkkggEdsb 
+s&hgsfdk; 
+d&Hyscvnm;
+
+Sample Output:
+THU 14:04
+
+
\ No newline at end of file diff --git a/html/a1062.html b/html/a1062.html new file mode 100644 index 0000000..a4c7587 --- /dev/null +++ b/html/a1062.html @@ -0,0 +1,20 @@ + + +

1062. Talent and Virtue (25)

+
+

+About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人)"; being less excellent but with one's virtue outweighs talent can be called a "nobleman(君子)"; being good in neither is a "fool man(愚人)"; yet a fool man is better than a "small man(小人)" who prefers talent than virtue. +

+

+Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang's theory. +

+

+Input Specification: +

+

Each input file contains one test case. Each case first gives 3 positive integers in a line: N (<=105), the total number of people to be ranked; L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (<100), the higher line of qualification -- that is, those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages". Those with both grades below H, but with virtue not lower than talent are considered as the "fool men". They are ranked in the same way but after the "noblemen". The rest of people whose grades both pass the L line are ranked after the "fool men". +

+

Then N lines follow, each gives the information of a person in the format:

+ID_Number Virtue_Grade Talent_Grade
+
+where ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space. +
\ No newline at end of file diff --git a/html/a1063.html b/html/a1063.html new file mode 100644 index 0000000..91dc054 --- /dev/null +++ b/html/a1063.html @@ -0,0 +1,27 @@ + + +

1063. Set Similarity (25)

+
+

Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.

+

+Input Specification: +

+

Each input file contains one test case. Each case first gives a positive integer N (<=50) which is the total number of sets. Then N lines follow, each gives a set with a positive M (<=104) and followed by M integers in the range [0, 109]. After the input of sets, a positive integer K (<=2000) is given, followed by K lines of queries. Each query gives a pair of set numbers (the sets are numbered from 1 to N). All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each query, print in one line the similarity of the sets, in the percentage form accurate up to 1 decimal place.

+Sample Input:
+3
+3 99 87 101
+4 87 101 5 87
+7 99 101 18 5 135 18 99
+2
+1 2
+1 3
+
+Sample Output:
+50.0%
+33.3%
+
+
\ No newline at end of file diff --git a/html/a1064.html b/html/a1064.html new file mode 100644 index 0000000..4a067f7 --- /dev/null +++ b/html/a1064.html @@ -0,0 +1,28 @@ + + +

1064. Complete Binary Search Tree (30)

+
+

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:

+ +

A Complete Binary Tree (CBT) is a tree that is completely filled, with the possible exception of the bottom level, which is filled from left to right.

+

Now given a sequence of distinct non-negative integer keys, a unique BST can be constructed if it is required that the tree must also be a CBT. You are supposed to output the level order traversal sequence of this BST.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains a positive integer N (<=1000). Then N distinct non-negative integer keys are given in the next line. All the numbers in a line are separated by a space and are no greater than 2000.

+

+Output Specification: +

+

For each test case, print in one line the level order traversal sequence of the corresponding complete binary search tree. All the numbers in a line must be separated by a space, and there must be no extra space at the end of the line. +

+Sample Input:
+10
+1 2 3 4 5 6 7 8 9 0
+
+Sample Output:
+6 3 8 1 5 7 9 0 2 4
+
+
\ No newline at end of file diff --git a/html/a1065.html b/html/a1065.html new file mode 100644 index 0000000..0990c3c --- /dev/null +++ b/html/a1065.html @@ -0,0 +1,27 @@ + + +

1065. A+B and C (64bit) (20)

+
+

Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C.

+

+Input Specification: +

+

The first line of the input gives the positive number of test cases, T (<=10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.

+

+Output Specification: +

+

For each test case, output in one line "Case #X: true" if A+B&gtC;, or "Case #X: false" otherwise, where X is the case number (starting from 1). + +

+Sample Input:
+3
+1 2 3
+2 3 4
+9223372036854775807 -9223372036854775808 0
+
+Sample Output:
+Case #1: false
+Case #2: true
+Case #3: false
+
+
\ No newline at end of file diff --git a/html/a1066.html b/html/a1066.html new file mode 100644 index 0000000..87dd1bb --- /dev/null +++ b/html/a1066.html @@ -0,0 +1,10 @@ + + +

1066. Root of AVL Tree (25)

+
+

An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. Figures 1-4 illustrate the rotation rules.

+
    
+

+
    
+

Now given a sequence of insertions, you are supposed to tell the root of the resulting AVL tree.

+
\ No newline at end of file diff --git a/html/a1067.html b/html/a1067.html new file mode 100644 index 0000000..f87f11d --- /dev/null +++ b/html/a1067.html @@ -0,0 +1,26 @@ + + +

1067. Sort with Swap(0,*) (25)

+
+

Given any permutation of the numbers {0, 1, 2,..., N-1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may apply the swap operations in the following way:

+

+Swap(0, 1) => {4, 1, 2, 0, 3}
+Swap(0, 3) => {4, 1, 2, 3, 0}
+Swap(0, 4) => {0, 1, 2, 3, 4} +

+

Now you are asked to find the minimum number of swaps need to sort the given permutation of the first N nonnegative integers.

+

+Input Specification: +

+

Each input file contains one test case, which gives a positive N (<=105) followed by a permutation sequence of {0, 1, ..., N-1}. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each case, simply print in a line the minimum number of swaps need to sort the given permutation.

+Sample Input:
+10 3 5 7 2 6 4 9 0 8 1
+
+Sample Output:
+9
+
+
\ No newline at end of file diff --git a/html/a1068.html b/html/a1068.html new file mode 100644 index 0000000..099616e --- /dev/null +++ b/html/a1068.html @@ -0,0 +1,29 @@ + + +

1068. Find More Coins (30)

+
+

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requirement of the payment: for each bill, she must pay the exact amount. Since she has as many as 104 coins with her, she definitely needs your help. You are supposed to tell her, for any given amount of money, whether or not she can find some coins to pay for it.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 positive numbers: N (<=104, the total number of coins) and M(<=102, the amount of money Eva has to pay). The second line contains N face values of the coins, which are all positive numbers. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print in one line the face values V1 <= V2 <= ... <= Vk such that V1 + V2 + ... + Vk = M. All the numbers must be separated by a space, and there must be no extra space at the end of the line. If such a solution is not unique, output the smallest sequence. If there is no solution, output "No Solution" instead.

+

Note: sequence {A[1], A[2], ...} is said to be "smaller" than sequence {B[1], B[2], ...} if there exists k >= 1 such that A[i]=B[i] for all i < k, and A[k] < B[k].

+Sample Input 1:
+8 9
+5 9 8 7 2 3 4 1
+
+Sample Output 1:
+1 3 5
+
+Sample Input 2:
+4 8
+7 2 4 3
+
+Sample Output 2:
+No Solution
+
+
\ No newline at end of file diff --git a/html/a1069.html b/html/a1069.html new file mode 100644 index 0000000..2a928ef --- /dev/null +++ b/html/a1069.html @@ -0,0 +1,38 @@ + + +

1069. The Black Hole of Numbers (20)

+
+

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in this manner we will soon end up at the number 6174 -- the "black hole" of 4-digit numbers. This number is named Kaprekar Constant.

+

For example, start from 6767, we'll get:

+

+7766 - 6677 = 1089
+9810 - 0189 = 9621
+9621 - 1269 = 8352
+8532 - 2358 = 6174
+7641 - 1467 = 6174
+... ...

+

Given any 4-digit number, you are supposed to illustrate the way it gets into the black hole.

+

+Input Specification: +

+

Each input file contains one test case which gives a positive integer N in the range (0, 10000).

+

+Output Specification: +

+

If all the 4 digits of N are the same, print in one line the equation "N - N = 0000". Else print each step of calculation in a line until 6174 comes out as the difference. All the numbers must be printed as 4-digit numbers.

+Sample Input 1:
+6767
+
+Sample Output 1:
+7766 - 6677 = 1089
+9810 - 0189 = 9621
+9621 - 1269 = 8352
+8532 - 2358 = 6174
+
+Sample Input 2:
+2222
+
+Sample Output 2:
+2222 - 2222 = 0000
+
+
\ No newline at end of file diff --git a/html/a1070.html b/html/a1070.html new file mode 100644 index 0000000..52e4377 --- /dev/null +++ b/html/a1070.html @@ -0,0 +1,23 @@ + + +

1070. Mooncake (25)

+
+

Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region's culture. Now given the inventory amounts and the prices of all kinds of the mooncakes, together with the maximum total demand of the market, you are supposed to tell the maximum profit that can be made.

+

Note: partial inventory storage can be taken. The sample shows the following situation: given three kinds of mooncakes with inventory amounts being 180, 150, and 100 thousand tons, and the prices being 7.5, 7.2, and 4.5 billion yuans. If the market demand can be at most 200 thousand tons, the best we can do is to sell 150 thousand tons of the second kind of mooncake, and 50 thousand tons of the third kind. Hence the total profit is 7.2 + 4.5/2 = 9.45 (billion yuans).

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 positive integers N (<=1000), the number of different kinds of mooncakes, and D (<=500 thousand tons), the maximum total demand of the market. Then the second line gives the positive inventory amounts (in thousand tons), and the third line gives the positive prices (in billion yuans) of N kinds of mooncakes. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, print the maximum profit (in billion yuans) in one line, accurate up to 2 decimal places.

+Sample Input:
+3 200
+180 150 100
+7.5 7.2 4.5
+
+Sample Output:
+9.45
+
+
\ No newline at end of file diff --git a/html/a1071.html b/html/a1071.html new file mode 100644 index 0000000..0a8fa3c --- /dev/null +++ b/html/a1071.html @@ -0,0 +1,27 @@ + + +

1071. Speech Patterns (25)

+
+

+People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker's identity, which is useful when validating, for example, whether it's still the same person behind an online avatar.

+

+Now given a paragraph of text sampled from someone's speech, can you find the person's most commonly used word?

+

+Input Specification: +

+

+Each input file contains one test case. For each case, there is one line of text no more than 1048576 characters in length, terminated by a carriage return '\n'. The input contains at least one alphanumerical character, i.e., one character from the set [0-9 A-Z a-z].

+

+Output Specification: +

+

+For each test case, print in one line the most commonly occurring word in the input text, followed by a space and the number of times it has occurred in the input. If there are more than one such words, print the lexicographically smallest one. The word should be printed in all lower case. Here a "word" is defined as a continuous sequence of alphanumerical characters separated by non-alphanumerical characters or the line beginning/end.

+

+Note that words are case insensitive.

+Sample Input:
+Can1: "Can a can can a can?  It can!"
+
+Sample Output:
+can 5
+
+
\ No newline at end of file diff --git a/html/a1072.html b/html/a1072.html new file mode 100644 index 0000000..21a1a5c --- /dev/null +++ b/html/a1072.html @@ -0,0 +1,45 @@ + + +

1072. Gas Station (30)

+
+

A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the houses are in its service range.

+

Now given the map of the city and several candidate locations for the gas station, you are supposed to give the best recommendation. If there are more than one solution, output the one with the smallest average distance to all the houses. If such a solution is still not unique, output the one with the smallest index number.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 4 positive integers: N (<= 103), the total number of houses; M (<= 10), the total number of the candidate locations for the gas stations; K (<= 104), the number of roads connecting the houses and the gas stations; and DS, the maximum service range of the gas station. It is hence assumed that all the houses are numbered from 1 to N, and all the candidate locations are numbered from G1 to GM.

+

Then K lines follow, each describes a road in the format
+P1 P2 Dist
+where P1 and P2 are the two ends of a road which can be either house numbers or gas station numbers, and Dist is the integer length of the road.

+

+Output Specification: +

+

For each test case, print in the first line the index number of the best location. In the next line, print the minimum and the average distances between the solution and all the houses. The numbers in a line must be separated by a space and be accurate up to 1 decimal place. If the solution does not exist, simply output “No Solution”. +

+Sample Input 1:
+4 3 11 5
+1 2 2
+1 4 2
+1 G1 4
+1 G2 3
+2 3 2
+2 G2 1
+3 4 2
+3 G3 2
+4 G1 3
+G2 G1 1
+G3 G2 2
+
+Sample Output 1:
+G1
+2.0 3.3
+
+Sample Input 2:
+2 1 2 10
+1 G1 9
+2 G1 20
+
+Sample Output 2:
+No Solution
+
+
\ No newline at end of file diff --git a/html/a1073.html b/html/a1073.html new file mode 100644 index 0000000..c609aa0 --- /dev/null +++ b/html/a1073.html @@ -0,0 +1,31 @@ + + +

1073. Scientific Notation (20)

+
+

+Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9]"."[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent's signs are always provided even when they are positive.

+

+Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.

+

+Input Specification: +

+

+Each input file contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent's absolute value is no more than 9999.

+

+Output Specification: +

+

+For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros,

+Sample Input 1:
++1.23400E-03
+
+Sample Output 1:
+0.00123400
+
+Sample Input 2:
+-1.2E+10
+
+Sample Output 2:
+-12000000000
+
+
\ No newline at end of file diff --git a/html/a1074.html b/html/a1074.html new file mode 100644 index 0000000..9c908d1 --- /dev/null +++ b/html/a1074.html @@ -0,0 +1,35 @@ + + +

1074. Reversing Linked List (25)

+
+

Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K = 3, then you must output 3→2→1→6→5→4; if K = 4, you must output 4→3→2→1→5→6.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (<= 105) which is the total number of nodes, and a positive K (<=N) which is the length of the sublist to be reversed. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

+

Then N lines follow, each describes a node in the format:

+

Address Data Next

+

where Address is the position of the node, Data is an integer, and Next is the position of the next node.

+

+Output Specification: +

+

For each case, output the resulting ordered linked list. Each node occupies a line, and is printed in the same format as in the input. +

+Sample Input:
+00100 6 4
+00000 4 99999
+00100 1 12309
+68237 6 -1
+33218 3 00000
+99999 5 68237
+12309 2 33218
+
+Sample Output:
+00000 4 33218
+33218 3 12309
+12309 2 00100
+00100 1 99999
+99999 5 68237
+68237 6 -1
+
+
\ No newline at end of file diff --git a/html/a1075.html b/html/a1075.html new file mode 100644 index 0000000..3abd277 --- /dev/null +++ b/html/a1075.html @@ -0,0 +1,56 @@ + + +

1075. PAT Judge (25)

+
+

The ranklist of PAT is generated from the status list, which shows the scores of the submittions. This time you are supposed to generate the ranklist for PAT. +

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 3 positive integers, N (<=104), the total number of users, K (<=5), the total number of problems, and M (<=105), the total number of submittions. It is then assumed that the user id's are 5-digit numbers from 00001 to N, and the problem id's are from 1 to K. The next line contains K positive integers p[i] (i=1, ..., K), where p[i] corresponds to the full mark of the i-th problem. Then M lines follow, each gives the information of a submittion in the following format:

+

+user_id problem_id partial_score_obtained

+

+where partial_score_obtained is either -1 if the submittion cannot even pass the compiler, or is an integer in the range [0, p[problem_id]]. All the numbers in a line are separated by a space.

+

+Output Specification: +

+

For each test case, you are supposed to output the ranklist in the following format:

+

+rank user_id total_score s[1] ... s[K]

+

+where rank is calculated according to the total_score, and all the users with the same total_score obtain the same rank; and s[i] is the partial score obtained for the i-th problem. If a user has never submitted a solution for a problem, then "-" must be printed at the corresponding position. If a user has submitted several solutions to solve one problem, then the highest score will be counted. +

+

The ranklist must be printed in non-decreasing order of the ranks. For those who have the same rank, users must be sorted in nonincreasing order according to the number of perfectly solved problems. And if there is still a tie, then they must be printed in increasing order of their id's. For those who has never submitted any solution that can pass the compiler, or has never submitted any solution, they must NOT be shown on the ranklist. It is guaranteed that at least one user can be shown on the ranklist.

+Sample Input:
+7 4 20
+20 25 25 30
+00002 2 12
+00007 4 17
+00005 1 19
+00007 2 25
+00005 1 20
+00002 2 2
+00005 1 15
+00001 1 18
+00004 3 25
+00002 2 25
+00005 3 22
+00006 4 -1
+00001 2 18
+00002 1 20
+00004 1 15
+00002 4 18
+00001 3 4
+00001 4 2
+00005 2 -1
+00004 2 0
+
+Sample Output:
+1 00002 63 20 25 - 18
+2 00005 42 20 0 22 -
+2 00007 42 - 25 - 17
+2 00001 42 18 18 4 2
+5 00004 40 15 0 25 -
+
+
\ No newline at end of file diff --git a/html/a1076.html b/html/a1076.html new file mode 100644 index 0000000..ae65df0 --- /dev/null +++ b/html/a1076.html @@ -0,0 +1,37 @@ + + +

1076. Forwards on Weibo (30)

+
+

Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all his/her followers can view and forward his/her post, which can then be forwarded again by their followers. Now given a social network, you are supposed to calculate the maximum potential amount of forwards for any specific user, assuming that only L levels of indirect followers are counted.

+

+Input Specification: +

+

Each input file contains one test case. For each case, the first line contains 2 positive integers: N (<=1000), the number of users; and L (<=6), the number of levels of indirect followers that are counted. Hence it is assumed that all the users are numbered from 1 to N. Then N lines follow, each in the format:

+

+M[i] user_list[i]

+

+where M[i] (<=100) is the total number of people that user[i] follows; and user_list[i] is a list of the M[i] users that are followed by user[i]. It is guaranteed that no one can follow oneself. All the numbers are separated by a space.

+

+Then finally a positive K is given, followed by K UserID's for query. +

+

+Output Specification: +

+

For each UserID, you are supposed to print in one line the maximum potential amount of forwards this user can triger, assuming that everyone who can view the initial post will forward it once, and that only L levels of indirect followers are counted. +

+Sample Input:
+7 3
+3 2 3 4
+0
+2 5 6
+2 3 1
+2 3 4
+1 4
+1 5
+2 2 6
+
+Sample Output:
+4
+5
+
+
\ No newline at end of file diff --git a/html/a1077.html b/html/a1077.html new file mode 100644 index 0000000..eb757c2 --- /dev/null +++ b/html/a1077.html @@ -0,0 +1,37 @@ + + +

1077. Kuchiguse (20)

+
+

+The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called "Kuchiguse" and is often exaggerated artistically in Anime and Manga. For example, the artificial sentence ending particle "nyan~" is often used as a stereotype for characters with a cat-like personality:

+
  • Itai nyan~ (It hurts, nyan~)
  • +
  • Ninjin wa iyada nyan~ (I hate carrots, nyan~)
  • +

    +Now given a few lines spoken by the same character, can you find her Kuchiguse?

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line is an integer N (2<=N<=100). Following are N file lines of 0~256 (inclusive) characters in length, each representing a character's spoken line. The spoken lines are case sensitive.

    +

    +Output Specification: +

    +

    For each test case, print in one line the kuchiguse of the character, i.e., the longest common suffix of all N lines. If there is no such suffix, write "nai".

    +Sample Input 1:
    +3
    +Itai nyan~
    +Ninjin wa iyadanyan~
    +uhhh nyan~
    +
    +Sample Output 1:
    +nyan~
    +
    +Sample Input 2:
    +3
    +Itai!
    +Ninjinnwaiyada T_T
    +T_T
    +
    +Sample Output 2:
    +nai
    +
    +
    \ No newline at end of file diff --git a/html/a1078.html b/html/a1078.html new file mode 100644 index 0000000..7007490 --- /dev/null +++ b/html/a1078.html @@ -0,0 +1,23 @@ + + +

    1078. Hashing (25)

    +
    +

    The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be "H(key) = key % TSize" where TSize is the maximum size of the hash table. Quadratic probing (with positive increments only) is used to solve the collisions.

    +

    Note that the table size is better to be prime. If the maximum size given by the user is not prime, you must re-define the table size to be the smallest prime number which is larger than the size given by the user.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains two positive numbers: MSize (<=104) and N (<=MSize) which are the user-defined table size and the number of input numbers, respectively. Then N distinct positive integers are given in the next line. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print the corresponding positions (index starts from 0) of the input numbers in one line. All the numbers in a line are separated by a space, and there must be no extra space at the end of the line. In case it is impossible to insert the number, print "-" instead. +

    +Sample Input:
    +4 4
    +10 6 4 15
    +
    +Sample Output:
    +0 1 4 -
    +
    +
    \ No newline at end of file diff --git a/html/a1079.html b/html/a1079.html new file mode 100644 index 0000000..aa5d00d --- /dev/null +++ b/html/a1079.html @@ -0,0 +1,37 @@ + + +

    1079. Total Sales of Supply Chain (25)

    +
    +

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.

    +

    +Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. Only the retailers will face the customers. +It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.

    +

    +Now given a supply chain, you are supposed to tell the total sales from all the retailers.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains three positive numbers: N (<=105), the total number of the members in the supply chain (and hence their ID's are numbered from 0 to N-1, and the root supplier's ID is 0); P, the unit price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:

    +

    Ki ID[1] ID[2] ... ID[Ki]

    +

    where in the i-th line, Ki is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. Kj being 0 means that the j-th member is a retailer, then instead the total amount of the product will be given after Kj. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print in one line the total sales we can expect from all the retailers, accurate up to 1 decimal place. It is guaranteed that the number will not exceed 1010.

    +Sample Input:
    +10 1.80 1.00
    +3 2 3 5
    +1 9
    +1 4
    +1 7
    +0 7
    +2 6 1
    +1 8
    +0 9
    +0 4
    +0 3
    +
    +Sample Output:
    +42.4
    +
    +
    \ No newline at end of file diff --git a/html/a1080.html b/html/a1080.html new file mode 100644 index 0000000..0325329 --- /dev/null +++ b/html/a1080.html @@ -0,0 +1,46 @@ + + +

    1080. Graduate Admission (30)

    +
    +

    It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.

    +

    Each applicant will have to provide two grades: the national entrance exam grade GE, and the interview grade GI. The final grade of an applicant is (GE + GI) / 2. The admission rules are:

    + +

    +Input Specification: +

    +

    Each input file contains one test case. Each case starts with a line containing three positive integers: N (<=40,000), the total number of applicants; M (<=100), the total number of graduate schools; and K (<=5), the number of choices an applicant may have.

    +

    In the next line, separated by a space, there are M positive integers. The i-th integer is the quota of the i-th graduate school respectively.

    +

    Then N lines follow, each contains 2+K integers separated by a space. The first 2 integers are the applicant's GE and GI, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 to M-1, and the applicants are numbered from 0 to N-1.

    +

    +Output Specification: +

    +

    For each test case you should output the admission results for all the graduate schools. The results of each school must occupy a line, which contains the applicants' numbers that school admits. The numbers must be in increasing order and be separated by a space. There must be no extra space at the end of each line. If no applicant is admitted by a school, you must output an empty line correspondingly.

    +Sample Input:
    +11 6 3
    +2 1 2 2 2 3
    +100 100 0 1 2
    +60 60 2 3 5
    +100 90 0 3 4
    +90 100 1 2 0
    +90 90 5 1 3
    +80 90 1 0 2
    +80 80 0 1 2
    +80 80 0 1 2
    +80 70 1 3 2
    +70 80 1 2 3
    +100 100 0 2 4
    +
    +Sample Output:
    +0 10
    +3
    +5 6 7
    +2 8
    +
    +1 4
    +
    +
    \ No newline at end of file diff --git a/html/a1081.html b/html/a1081.html new file mode 100644 index 0000000..af24092 --- /dev/null +++ b/html/a1081.html @@ -0,0 +1,36 @@ + + +

    1081. Rational Sum (20)

    +
    +

    +Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum.

    +

    +Input Specification: +

    +

    Each input file contains one test case. Each case starts with a positive integer N (<=100), followed in the next line N rational numbers "a1/b1 a2/b2 ..." where all the numerators and denominators are in the range of "long int". If there is a negative number, then the sign must appear in front of the numerator.

    +

    +Output Specification: +

    +

    For each test case, output the sum in the simplest form "integer numerator/denominator" where "integer" is the integer part of the sum, "numerator" < "denominator", and the numerator and the denominator have no common factor. You must output only the fractional part if the integer part is 0.

    +Sample Input 1:
    +5
    +2/5 4/15 1/30 -2/60 8/3
    +
    +Sample Output 1:
    +3 1/3
    +
    +Sample Input 2:
    +2
    +4/3 2/3
    +
    +Sample Output 2:
    +2
    +
    +Sample Input 3:
    +3
    +1/3 -1/6 1/8
    +
    +Sample Output 3:
    +7/24
    +
    +
    \ No newline at end of file diff --git a/html/a1082.html b/html/a1082.html new file mode 100644 index 0000000..0fa3eeb --- /dev/null +++ b/html/a1082.html @@ -0,0 +1,26 @@ + + +

    1082. Read Number in Chinese (25)

    +
    +

    Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is read as "Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu". Note: zero ("ling") must be handled correctly according to the Chinese tradition. For example, 100800 is "yi Shi Wan ling ba Bai".

    +

    +Input Specification: +

    +

    Each input file contains one test case, which gives an integer with no more than 9 digits.

    +

    +Output Specification: +

    +

    For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.

    +Sample Input 1:
    +-123456789
    +
    +Sample Output 1:
    +Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
    +
    +Sample Input 2:
    +100800
    +
    +Sample Output 2:
    +yi Shi Wan ling ba Bai
    +
    +
    \ No newline at end of file diff --git a/html/a1083.html b/html/a1083.html new file mode 100644 index 0000000..dc170e1 --- /dev/null +++ b/html/a1083.html @@ -0,0 +1,44 @@ + + +

    1083. List Grades (25)

    +
    +

    Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades are in a given interval.

    +

    +Input Specification: +

    +

    Each input file contains one test case. Each case is given in the following format:

    +N
    +name[1] ID[1] grade[1]
    +name[2] ID[2] grade[2]
    +... ...
    +name[N] ID[N] grade[N]
    +grade1 grade2
    +
    +

    where name[i] and ID[i] are strings of no more than 10 characters with no space, grade[i] is an integer in [0, 100], grade1 and grade2 are the boundaries of the grade's interval. It is guaranteed that all the grades are distinct.

    +

    +Output Specification: +

    +

    For each test case you should output the student records of which the grades are in the given interval [grade1, grade2] and are in non-increasing order. Each student record occupies a line with the student's name and ID, separated by one space. If there is no student's grade in that interval, output "NONE" instead.

    +Sample Input 1:
    +4
    +Tom CS000001 59
    +Joe Math990112 89
    +Mike CS991301 100
    +Mary EE990830 95
    +60 100
    +
    +Sample Output 1:
    +Mike CS991301
    +Mary EE990830
    +Joe Math990112
    +
    +Sample Input 2:
    +2
    +Jean AA980920 60
    +Ann CS01 80
    +90 95
    +
    +Sample Output 2:
    +NONE
    +
    +
    \ No newline at end of file diff --git a/html/a1084.html b/html/a1084.html new file mode 100644 index 0000000..af45230 --- /dev/null +++ b/html/a1084.html @@ -0,0 +1,27 @@ + + +

    1084. Broken Keyboard (20)

    +
    +

    +On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.

    +

    Now given a string that you are supposed to type, and the string that you actually type out, please list those keys which are for sure worn out. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the 1st line contains the original string, and the 2nd line contains the typed-out string. Each string contains no more than 80 characters which are either English letters [A-Z] (case insensitive), digital numbers [0-9], or "_" (representing the space). It is guaranteed that both strings are non-empty. +

    +

    +Output Specification: +

    +

    +For each test case, print in one line the keys that are worn out, in the order of being detected. The English letters must be capitalized. Each worn out key must be printed once only. It is guaranteed that there is at least one worn out key. +

    +Sample Input:
    +7_This_is_a_test
    +_hs_s_a_es
    +
    +Sample Output:
    +7TI
    +
    +
    \ No newline at end of file diff --git a/html/a1085.html b/html/a1085.html new file mode 100644 index 0000000..728f194 --- /dev/null +++ b/html/a1085.html @@ -0,0 +1,25 @@ + + +

    1085. Perfect Sequence (25)

    +
    +

    +Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M <= m * p where M and m are the maximum and minimum numbers in the sequence, respectively. +

    +

    Now given a sequence and a parameter p, you are supposed to find from the sequence as many numbers as possible to form a perfect subsequence. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains two positive integers N and p, where N (<= 105) is the number of integers in the sequence, and p (<= 109) is the parameter. In the second line there are N positive integers, each is no greater than 109.

    +

    +Output Specification: +

    +

    For each test case, print in one line the maximum number of integers that can be chosen to form a perfect subsequence.

    +Sample Input:
    +10 8
    +2 3 20 4 5 1 6 7 8 9
    +
    +Sample Output:
    +8
    +
    +
    \ No newline at end of file diff --git a/html/a1086.html b/html/a1086.html new file mode 100644 index 0000000..906a78c --- /dev/null +++ b/html/a1086.html @@ -0,0 +1,35 @@ + + +

    1086. Tree Traversals Again (25)

    +
    +

    An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push(1); push(2); push(3); pop(); pop(); push(4); pop(); pop(); push(5); push(6); pop(); pop(). Then a unique binary tree (shown in Figure 1) can be generated from this sequence of operations. Your task is to give the postorder traversal sequence of this tree. +

    +

    Figure 1
    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains a positive integer N (<=30) which is the total number of nodes in a tree (and hence the nodes are numbered from 1 to N). Then 2N lines follow, each describes a stack operation in the format: "Push X" where X is the index of the node being pushed onto the stack; or "Pop" meaning to pop one node from the stack.

    +

    +Output Specification: +

    +

    For each test case, print the postorder traversal sequence of the corresponding tree in one line. A solution is guaranteed to exist. All the numbers must be separated by exactly one space, and there must be no extra space at the end of the line. +

    +Sample Input:
    +6
    +Push 1
    +Push 2
    +Push 3
    +Pop
    +Pop
    +Push 4
    +Pop
    +Pop
    +Push 5
    +Push 6
    +Pop
    +Pop
    +
    +Sample Output:
    +3 4 2 6 5 1
    +
    +
    \ No newline at end of file diff --git a/html/a1087.html b/html/a1087.html new file mode 100644 index 0000000..9b1e1cd --- /dev/null +++ b/html/a1087.html @@ -0,0 +1,35 @@ + + +

    1087. All Roads Lead to Rome (30)

    +
    +

    Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains 2 positive integers N (2<=N<=200), the number of cities, and K, the total number of routes between pairs of cities; followed by the name of the starting city. The next N-1 lines each gives the name of a city and an integer that represents the happiness one can gain from that city, except the starting city. Then K lines follow, each describes a route between two cities in the format "City1 City2 Cost". Here the name of a city is a string of 3 capital English letters, and the destination is always ROM which represents Rome.

    +

    +Output Specification: +

    +

    For each test case, we are supposed to find the route with the least cost. If such a route is not unique, the one with the maximum happiness will be recommended. If such a route is still not unique, then we output the one with the maximum average happiness -- it is guaranteed by the judge that such a solution exists and is unique.

    +

    Hence in the first line of output, you must print 4 numbers: the number of different routes with the least cost, the cost, the happiness, and the average happiness (take the integer part only) of the recommended route. Then in the next line, you are supposed to print the route in the format "City1->City2->...->ROM". +

    +Sample Input:
    +6 7 HZH
    +ROM 100
    +PKN 40
    +GDN 55
    +PRS 95
    +BLN 80
    +ROM GDN 1
    +BLN ROM 1
    +HZH PKN 1
    +PRS ROM 2
    +BLN HZH 2
    +PKN GDN 1
    +HZH PRS 1
    +
    +Sample Output:
    +3 3 195 97
    +HZH->PRS->ROM
    +
    +
    \ No newline at end of file diff --git a/html/a1088.html b/html/a1088.html new file mode 100644 index 0000000..2b08248 --- /dev/null +++ b/html/a1088.html @@ -0,0 +1,32 @@ + + +

    1088. Rational Arithmetic (20)

    +
    +

    For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.

    +

    +Input Specification: +

    +

    Each input file contains one test case, which gives in one line the two rational numbers in the format "a1/b1 a2/b2". The numerators and the denominators are all in the range of long int. If there is a negative sign, it must appear only in front of the numerator. The denominators are guaranteed to be non-zero numbers.

    +

    +Output Specification: +

    +

    For each test case, print in 4 lines the sum, difference, product and quotient of the two rational numbers, respectively. The format of each line is "number1 operator number2 = result". Notice that all the rational numbers must be in their simplest form "k a/b", where k is the integer part, and a/b is the simplest fraction part. If the number is negative, it must be included in a pair of parentheses. If the denominator in the division is zero, output "Inf" as the result. It is guaranteed that all the output integers are in the range of long int.

    +Sample Input 1:
    +2/3 -4/2
    +
    +Sample Output 1:
    +2/3 + (-2) = (-1 1/3)
    +2/3 - (-2) = 2 2/3
    +2/3 * (-2) = (-1 1/3)
    +2/3 / (-2) = (-1/3)
    +
    +Sample Input 2:
    +5/3 0/6
    +
    +Sample Output 2:
    +1 2/3 + 0 = 1 2/3
    +1 2/3 - 0 = 1 2/3
    +1 2/3 * 0 = 0
    +1 2/3 / 0 = Inf
    +
    +
    \ No newline at end of file diff --git a/html/a1089.html b/html/a1089.html new file mode 100644 index 0000000..ede5deb --- /dev/null +++ b/html/a1089.html @@ -0,0 +1,36 @@ + + +

    1089. Insert or Merge (25)

    +
    +

    According to Wikipedia:

    +

    Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

    +

    +Merge sort works as follows: Divide the unsorted list into N sublists, each containing 1 element (a list of 1 element is considered sorted). Then repeatedly merge two adjacent sublists to produce new sorted sublists until there is only 1 sublist remaining.

    +

    Now given the initial sequence of integers, together with a sequence which is a result of several iterations of some sorting method, can you tell which sorting method we are using?

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=100). Then in the next line, N integers are given as the initial sequence. The last line contains the partially sorted sequence of the N numbers. It is assumed that the target sequence is always ascending. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print in the first line either "Insertion Sort" or "Merge Sort" to indicate the method used to obtain the partial result. Then run this method for one more iteration and output in the second line the resulting sequence. It is guaranteed that the answer is unique for each test case. All the numbers in a line must be separated by a space, and there must be no extra space at the end of the line.

    +Sample Input 1:
    +10
    +3 1 2 8 7 5 9 4 6 0
    +1 2 3 7 8 5 9 4 6 0
    +
    +Sample Output 1:
    +Insertion Sort
    +1 2 3 5 7 8 9 4 6 0
    +
    +Sample Input 2:
    +10
    +3 1 2 8 7 5 9 4 0 6
    +1 3 2 8 5 7 4 9 0 6
    +
    +Sample Output 2:
    +Merge Sort
    +1 2 3 8 4 5 7 9 0 6
    +
    +
    \ No newline at end of file diff --git a/html/a1090.html b/html/a1090.html new file mode 100644 index 0000000..23bbd62 --- /dev/null +++ b/html/a1090.html @@ -0,0 +1,26 @@ + + +

    1090. Highest Price in Supply Chain (25)

    +
    +

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.

    +

    +Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. +It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.

    +

    +Now given a supply chain, you are supposed to tell the highest price we can expect from some retailers.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, The first line contains three positive numbers: N (<=105), the total number of the members in the supply chain (and hence they are numbered from 0 to N-1); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers, each number Si is the index of the supplier for the i-th member. Sroot for the root supplier is defined to be -1. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print in one line the highest price we can expect from some retailers, accurate up to 2 decimal places, and the number of retailers that sell at the highest price. There must be one space between the two numbers. It is guaranteed that the price will not exceed 1010.

    +Sample Input:
    +9 1.80 1.00
    +1 5 4 4 -1 4 5 3 6
    +
    +Sample Output:
    +1.85 2
    +
    +
    \ No newline at end of file diff --git a/html/a1091.html b/html/a1091.html new file mode 100644 index 0000000..1d041f6 --- /dev/null +++ b/html/a1091.html @@ -0,0 +1,40 @@ + + +

    1091. Acute Stroke (30)

    +
    +

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the stroke core.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains 4 positive integers: M, N, L and T, where M and N are the sizes of each slice (i.e. pixels of a slice are in an M by N matrix, and the maximum resolution is 1286 by 128); L (<=60) is the number of slices of a brain; and T is the integer threshold (i.e. if the volume of a connected core is less than T, then that core must not be counted).

    +

    +Then L slices are given. Each slice is represented by an M by N matrix of 0's and 1's, where 1 represents a pixel of stroke, and 0 means normal. Since the thickness of a slice is a constant, we only have to count the number of 1's to obtain the volume. However, there might be several separated core regions in a brain, and only those with their volumes no less than T are counted. Two pixels are "connected" and hence belong to the same region if they share a common side, as shown by Figure 1 where all the 6 red pixels are connected to the blue one. +

    +

    Figure 1
    +

    +Output Specification: +

    +

    For each case, output in a line the total volume of the stroke core. +

    +Sample Input:
    +3 4 5 2
    +1 1 1 1
    +1 1 1 1
    +1 1 1 1
    +0 0 1 1
    +0 0 1 1
    +0 0 1 1
    +1 0 1 1
    +0 1 0 0
    +0 0 0 0
    +1 0 1 1
    +0 0 0 0
    +0 0 0 0
    +0 0 0 1
    +0 0 0 1
    +1 0 0 0
    +
    +Sample Output:
    +26
    +
    +
    \ No newline at end of file diff --git a/html/a1092.html b/html/a1092.html new file mode 100644 index 0000000..0154f13 --- /dev/null +++ b/html/a1092.html @@ -0,0 +1,30 @@ + + +

    1092. To Buy or Not to Buy (20)

    +
    +

    Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in whole pieces. Hence Eva must check whether a string in the shop contains all the beads she needs. She now comes to you for help: if the answer is "Yes", please tell her the number of extra beads she has to buy; or if the answer is "No", please tell her the number of beads missing from the string.

    +

    For the sake of simplicity, let's use the characters in the ranges [0-9], [a-z], and [A-Z] to represent the colors. For example, the 3rd string in Figure 1 is the one that Eva would like to make. Then the 1st string is okay since it contains all the necessary beads with 8 extra ones; yet the 2nd one is not since there is no black bead and one less red bead.

    +

    Figure 1
    +

    +Input Specification: +

    +

    Each input file contains one test case. Each case gives in two lines the strings of no more than 1000 beads which belong to the shop owner and Eva, respectively.

    +

    +Output Specification: +

    +

    For each test case, print your answer in one line. If the answer is "Yes", then also output the number of extra beads Eva has to buy; or if the answer is "No", then also output the number of beads missing from the string. There must be exactly 1 space between the answer and the number.

    +Sample Input 1:
    +ppRYYGrrYBR2258
    +YrR8RrY
    +
    +Sample Output 1:
    +Yes 8
    +
    +Sample Input 2:
    +ppRYYGrrYB225
    +YrR8RrY
    +
    +Sample Output 1:
    +No 2
    +
    +
    \ No newline at end of file diff --git a/html/a1093.html b/html/a1093.html new file mode 100644 index 0000000..4f0d50a --- /dev/null +++ b/html/a1093.html @@ -0,0 +1,26 @@ + + +

    1093. Count PAT's (25)

    +
    +

    +The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters. +

    +

    Now given any string, you are supposed to tell the number of PAT's contained in the string.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, there is only one line giving a string of no more than 105 characters containing only P, A, or T. +

    +

    +Output Specification: +

    +

    +For each test case, print in one line the number of PAT's contained in the string. Since the result may be a huge number, you only have to output the result moded by 1000000007. +

    +Sample Input:
    +APPAPT
    +
    +Sample Output:
    +2
    +
    +
    \ No newline at end of file diff --git a/html/a1094.html b/html/a1094.html new file mode 100644 index 0000000..88a848b --- /dev/null +++ b/html/a1094.html @@ -0,0 +1,37 @@ + + +

    1094. The Largest Generation (25)

    +
    +

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.

    +

    +Input Specification: +

    +

    Each input file contains one test case. Each case starts with two positive integers N (&lt100;) which is the total number of family members in the tree (and hence assume that all the members are numbered from 01 to N), and M (&ltN;) which is the number of family members who have children. Then M lines follow, each contains the information of a family member in the following format:

    +

    +ID K ID[1] ID[2] ... ID[K] +

    +

    where ID is a two-digit number representing a family member, K (&gt0;) is the number of his/her children, followed by a sequence of two-digit ID's of his/her children. For the sake of simplicity, let us fix the root ID to be 01. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print in one line the largest population number and the level of the corresponding generation. It is assumed that such a generation is unique, and the root level is defined to be 1.

    +Sample Input:
    +23 13
    +21 1 23
    +01 4 03 02 04 05
    +03 3 06 07 08
    +06 2 12 13
    +13 1 21
    +08 2 15 16
    +02 2 09 10
    +11 2 19 20
    +17 1 22
    +05 1 11
    +07 1 14
    +09 1 17
    +10 1 18
    +
    +Sample Output:
    +9 4
    +
    +
    \ No newline at end of file diff --git a/html/a1095.html b/html/a1095.html new file mode 100644 index 0000000..35ea39c --- /dev/null +++ b/html/a1095.html @@ -0,0 +1,56 @@ + + +

    1095. Cars on Campus (30)

    +
    +

    Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at any specific time point, the number of cars parking on campus, and at the end of the day find the cars that have parked for the longest time period.

    +

    +Input Specification: +

    +

    Each input file contains one test case. Each case starts with two positive integers N (<= 10000), the number of records, and K (<= 80000) the number of queries. Then N lines follow, each gives a record in the format

    +

    plate_number hh:mm:ss status

    +

    where plate_number is a string of 7 English capital letters or 1-digit numbers; hh:mm:ss represents the time point in a day by hour:minute:second, with the earliest time being 00:00:00 and the latest 23:59:59; and status is either in or out.

    +

    Note that all times will be within a single day. Each "in" record is paired with the chronologically next record for the same car provided it is an "out" record. Any "in" records that are not paired with an "out" record are ignored, as are "out" records not paired with an "in" record. It is guaranteed that at least one car is well paired in the input, and no car is both "in" and "out" at the same moment. Times are recorded using a 24-hour clock. +

    +

    +Then K lines of queries follow, each gives a time point in the format hh:mm:ss. Note: the queries are given in ascending order of the times.

    +

    +Output Specification: +

    +

    For each query, output in a line the total number of cars parking on campus. The last line of output is supposed to give the plate number of the car that has parked for the longest time period, and the corresponding time length. If such a car is not unique, then output all of their plate numbers in a line in alphabetical order, separated by a space.

    +Sample Input:
    +16 7
    +JH007BD 18:00:01 in
    +ZD00001 11:30:08 out
    +DB8888A 13:00:00 out
    +ZA3Q625 23:59:50 out
    +ZA133CH 10:23:00 in
    +ZD00001 04:09:59 in
    +JH007BD 05:09:59 in
    +ZA3Q625 11:42:01 out
    +JH007BD 05:10:33 in
    +ZA3Q625 06:30:50 in
    +JH007BD 12:23:42 out
    +ZA3Q625 23:55:00 in
    +JH007BD 12:24:23 out
    +ZA133CH 17:11:22 out
    +JH007BD 18:07:01 out
    +DB8888A 06:30:50 in
    +05:10:00
    +06:30:50
    +11:00:00
    +12:23:42
    +14:00:00
    +18:00:00
    +23:59:00
    +
    +Sample Output:
    +1
    +4
    +5
    +2
    +1
    +0
    +1
    +JH007BD ZD00001 07:20:09
    +
    +
    \ No newline at end of file diff --git a/html/a1096.html b/html/a1096.html new file mode 100644 index 0000000..a8cfe21 --- /dev/null +++ b/html/a1096.html @@ -0,0 +1,23 @@ + + +

    1096. Consecutive Factors (20)

    +
    +

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maximum number of consecutive factors, and list the smallest sequence of the consecutive factors. +

    +

    +Input Specification: +

    +

    Each input file contains one test case, which gives the integer N (1<N<231).

    +

    +Output Specification: +

    +

    For each test case, print in the first line the maximum number of consecutive factors. Then in the second line, print the smallest sequence of the consecutive factors in the format "factor[1]*factor[2]*...*factor[k]", where the factors are listed in increasing order, and 1 is NOT included. +

    +Sample Input:
    +630
    +
    +Sample Output:
    +3
    +5*6*7
    +
    +
    \ No newline at end of file diff --git a/html/a1097.html b/html/a1097.html new file mode 100644 index 0000000..7f683d2 --- /dev/null +++ b/html/a1097.html @@ -0,0 +1,33 @@ + + +

    1097. Deduplication on a Linked List (25)

    +
    +

    Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or absolute value of its key equals K will be kept. At the mean time, all the removed nodes must be kept in a separate list. For example, given L being 21→-15→-15→-7→15, you must output 21→-15→-7, and the removed list -15→15.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains the address of the first node, and a positive N (<= 105) which is the total number of nodes. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

    +

    Then N lines follow, each describes a node in the format:

    +

    Address Key Next

    +

    where Address is the position of the node, Key is an integer of which absolute value is no more than 104, and Next is the position of the next node.

    +

    +Output Specification: +

    +

    For each case, output the resulting linked list first, then the removed list. Each node occupies a line, and is printed in the same format as in the input. +

    +Sample Input:
    +00100 5
    +99999 -7 87654
    +23854 -15 00000
    +87654 15 -1
    +00000 -15 99999
    +00100 21 23854
    +
    +Sample Output:
    +00100 21 23854
    +23854 -15 99999
    +99999 -7 -1
    +00000 -15 87654
    +87654 15 -1
    +
    +
    \ No newline at end of file diff --git a/html/a1098.html b/html/a1098.html new file mode 100644 index 0000000..f3e792d --- /dev/null +++ b/html/a1098.html @@ -0,0 +1,36 @@ + + +

    1098. Insertion or Heap Sort (25)

    +
    +

    According to Wikipedia:

    +

    Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

    +

    +Heap sort divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region. it involves the use of a heap data structure rather than a linear-time search to find the maximum.

    +

    Now given the initial sequence of integers, together with a sequence which is a result of several iterations of some sorting method, can you tell which sorting method we are using?

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=100). Then in the next line, N integers are given as the initial sequence. The last line contains the partially sorted sequence of the N numbers. It is assumed that the target sequence is always ascending. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print in the first line either "Insertion Sort" or "Heap Sort" to indicate the method used to obtain the partial result. Then run this method for one more iteration and output in the second line the resuling sequence. It is guaranteed that the answer is unique for each test case. All the numbers in a line must be separated by a space, and there must be no extra space at the end of the line.

    +Sample Input 1:
    +10
    +3 1 2 8 7 5 9 4 6 0
    +1 2 3 7 8 5 9 4 6 0
    +
    +Sample Output 1:
    +Insertion Sort
    +1 2 3 5 7 8 9 4 6 0
    +
    +Sample Input 2:
    +10
    +3 1 2 8 7 5 9 4 6 0
    +6 4 5 1 0 3 2 7 8 9
    +
    +Sample Output 2:
    +Heap Sort
    +5 4 3 1 0 2 6 7 8 9
    +
    +
    \ No newline at end of file diff --git a/html/a1099.html b/html/a1099.html new file mode 100644 index 0000000..1482f66 --- /dev/null +++ b/html/a1099.html @@ -0,0 +1,38 @@ + + +

    1099. Build A Binary Search Tree (30)

    +
    +

    A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:

    +
  • The left subtree of a node contains only nodes with keys less than the node's key. +
  • The right subtree of a node contains only nodes with keys greater than or equal to the node's key. +
  • Both the left and right subtrees must also be binary search trees. + +

    Given the structure of a binary tree and a sequence of distinct integer keys, there is only one way to fill these keys into the tree so that the resulting tree satisfies the definition of a BST. You are supposed to output the level order traversal sequence of that tree. The sample is illustrated by Figure 1 and 2. +

    +
    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=100) which is the total number of nodes in the tree. The next N lines each contains the left and the right children of a node in the format "left_index right_index", provided that the nodes are numbered from 0 to N-1, and 0 is always the root. If one child is missing, then -1 will represent the NULL child pointer. Finally N distinct integer keys are given in the last line.

    +

    +Output Specification: +

    +

    For each test case, print in one line the level order traversal sequence of that tree. All the numbers must be separated by a space, with no extra space at the end of the line. +

    +Sample Input:
    +9
    +1 6
    +2 3
    +-1 -1
    +-1 4
    +5 -1
    +-1 -1
    +7 -1
    +-1 8
    +-1 -1
    +73 45 11 58 82 25 67 38 42
    +
    +Sample Output:
    +58 25 82 11 38 67 45 73 42
    +
    +
  • \ No newline at end of file diff --git a/html/a1100.html b/html/a1100.html new file mode 100644 index 0000000..e737d09 --- /dev/null +++ b/html/a1100.html @@ -0,0 +1,33 @@ + + +

    1100. Mars Numbers (20)

    +
    +

    People on Mars count their numbers with base 13:

    + +

    For examples, the number 29 on Earth is called "hel mar" on Mars; and "elo nov" on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains a positive integer N (< 100). Then N lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.

    +

    +Output Specification: +

    +

    For each number, print in a line the corresponding number in the other language.

    +Sample Input:
    +4
    +29
    +5
    +elo nov
    +tam
    +
    +Sample Output:
    +hel mar
    +may
    +115
    +13
    +
    +
    \ No newline at end of file diff --git a/html/a1101.html b/html/a1101.html new file mode 100644 index 0000000..9e967e4 --- /dev/null +++ b/html/a1101.html @@ -0,0 +1,30 @@ + + +

    1101. Quick Sort (25)

    +
    +

    There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the pivot to its right. +Given N distinct positive integers after a run of partition, could you tell how many elements could be the selected pivot for this partition?

    +

    For example, given N = 5 and the numbers 1, 3, 2, 4, and 5. We have:

    +

    +

  • 1 could be the pivot since there is no element to its left and all the elements to its right are larger than it;
    +
  • 3 must not be the pivot since although all the elements to its left are smaller, the number 2 to its right is less than it as well;
    +
  • 2 must not be the pivot since although all the elements to its right are larger, the number 3 to its left is larger than it as well;
    +
  • and for the similar reason, 4 and 5 could also be the pivot.
    +

    Hence in total there are 3 pivot candidates.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<= 105). Then the next line contains N distinct positive integers no larger than 109. The numbers in a line are separated by spaces.

    +

    +Output Specification: +

    +

    For each test case, output in the first line the number of pivot candidates. Then in the next line print these candidates in increasing order. There must be exactly 1 space between two adjacent numbers, and no extra space at the end of each line.

    +Sample Input:
    +5
    +1 3 2 4 5
    +
    +Sample Output:
    +3
    +1 4 5
    +
    +
  • \ No newline at end of file diff --git a/html/a1102.html b/html/a1102.html new file mode 100644 index 0000000..aa69d73 --- /dev/null +++ b/html/a1102.html @@ -0,0 +1,31 @@ + + +

    1102. Invert a Binary Tree (25)

    +
    +

    The following is from Max Howell @twitter:

    +

    Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off.

    +

    Now it's your turn to prove that YOU CAN invert a binary tree!

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=10) which is the total number of nodes in the tree -- and hence the nodes are numbered from 0 to N-1. Then N lines follow, each corresponds to a node from 0 to N-1, and gives the indices of the left and right children of the node. If the child does not exist, a "-" will be put at the position. Any pair of children are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print in the first line the level-order, and then in the second line the in-order traversal sequences of the inverted tree. There must be exactly one space between any adjacent numbers, and no extra space at the end of the line.

    +Sample Input:
    +8
    +1 -
    +- -
    +0 -
    +2 7
    +- -
    +- -
    +5 -
    +4 6
    +
    +Sample Output:
    +3 7 2 6 4 0 5 1
    +6 5 7 4 3 2 0 1
    +
    +
    \ No newline at end of file diff --git a/html/a1103.html b/html/a1103.html new file mode 100644 index 0000000..beffe92 --- /dev/null +++ b/html/a1103.html @@ -0,0 +1,37 @@ + + +

    1103. Integer Factorization (30)

    +
    +

    The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K-P factorization of N for any positive integers N, K and P.

    +

    +Input Specification: +

    +

    Each input file contains one test case which gives in a line the three positive integers N (<=400), K (<=N) and P (1<P<=7). The numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each case, if the solution exists, output in the format:

    +

    +N = n1^P + ... nK^P +

    +

    +where ni (i=1, ... K) is the i-th factor. All the factors must be printed in non-increasing order.

    +

    +Note: the solution may not be unique. For example, the 5-2 factorization of 169 has 9 solutions, such as 122 + 42 + 22 + 22 + 12, or 112 + 62 + 22 + 22 + 22, or more. You must output the one with the maximum sum of the factors. If there is a tie, the largest factor sequence must be chosen -- sequence { a1, a2, ... aK } is said to be larger than { b1, b2, ... bK } if there exists 1<=L<=K such that ai=bi for i<L and aL>bL +

    +

    +If there is no solution, simple output "Impossible". +

    +Sample Input 1:
    +169 5 2
    +
    +Sample Output 1:
    +169 = 6^2 + 6^2 + 6^2 + 6^2 + 5^2
    +
    +Sample Input 2:
    +169 167 3
    +
    +Sample Output 2:
    +Impossible
    +
    +
    \ No newline at end of file diff --git a/html/a1104.html b/html/a1104.html new file mode 100644 index 0000000..87c4ad2 --- /dev/null +++ b/html/a1104.html @@ -0,0 +1,25 @@ + + +

    1104. Sum of Number Segments (20)

    +
    +

    +Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence {0.1, 0.2, 0.3, 0.4}, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) (0.4). +

    +

    Now given a sequence, you are supposed to find the sum of all the numbers in all the segments. For the previous example, the sum of all the 10 segments is 0.1 + 0.3 + 0.6 + 1.0 + 0.2 + 0.5 + 0.9 + 0.3 + 0.7 + 0.4 = 5.0. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N, the size of the sequence which is no more than 105. The next line contains N positive numbers in the sequence, each no more than 1.0, separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print in one line the sum of all the numbers in all the segments, accurate up to 2 decimal places.

    +Sample Input:
    +4
    +0.1 0.2 0.3 0.4 
    +
    +Sample Output:
    +5.00
    +
    +
    \ No newline at end of file diff --git a/html/a1105.html b/html/a1105.html new file mode 100644 index 0000000..a9b103b --- /dev/null +++ b/html/a1105.html @@ -0,0 +1,25 @@ + + +

    1105. Spiral Matrix (25)

    +
    +

    This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in a clockwise spiral. The matrix has m rows and n columns, where m and n satisfy the following: m*n must be equal to N; m>=n; and m-n is the minimum of all the possible values.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N. Then the next line contains N positive integers to be filled into the spiral matrix. All the numbers are no more than 104. The numbers in a line are separated by spaces.

    +

    +Output Specification: +

    +

    For each test case, output the resulting matrix in m lines, each contains n numbers. There must be exactly 1 space between two adjacent numbers, and no extra space at the end of each line. +

    +Sample Input:
    +12
    +37 76 20 98 76 42 53 95 60 81 58 93
    +
    +Sample Output:
    +98 95 93
    +42 37 81
    +53 20 76
    +58 60 76
    +
    +
    \ No newline at end of file diff --git a/html/a1106.html b/html/a1106.html new file mode 100644 index 0000000..8d34d8a --- /dev/null +++ b/html/a1106.html @@ -0,0 +1,37 @@ + + +

    1106. Lowest Price in Supply Chain (25)

    +
    +

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.

    +

    +Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. Only the retailers will face the customers. +It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.

    +

    +Now given a supply chain, you are supposed to tell the lowest price a customer can expect from some retailers.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, The first line contains three positive numbers: N (<=105), the total number of the members in the supply chain (and hence their ID's are numbered from 0 to N-1, and the root supplier's ID is 0); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:

    +

    Ki ID[1] ID[2] ... ID[Ki]

    +

    where in the i-th line, Ki is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. Kj being 0 means that the j-th member is a retailer. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print in one line the lowest price we can expect from some retailers, accurate up to 4 decimal places, and the number of retailers that sell at the lowest price. There must be one space between the two numbers. It is guaranteed that the all the prices will not exceed 1010.

    +Sample Input:
    +10 1.80 1.00
    +3 2 3 5
    +1 9
    +1 4
    +1 7
    +0
    +2 6 1
    +1 8
    +0
    +0
    +0
    +
    +Sample Output:
    +1.8362 2
    +
    +
    \ No newline at end of file diff --git a/html/a1107.html b/html/a1107.html new file mode 100644 index 0000000..52efb7e --- /dev/null +++ b/html/a1107.html @@ -0,0 +1,33 @@ + + +

    1107. Social Clusters (30)

    +
    +

    When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A "social cluster" is a set of people who have some of their hobbies in common. You are supposed to find all the clusters.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each test case, the first line contains a positive integer N (<=1000), the total number of people in a social network. Hence the people are numbered from 1 to N. Then N lines follow, each gives the hobby list of a person in the format:

    +

    +Ki: hi[1] hi[2] ... hi[Ki]

    +

    where Ki (>0) is the number of hobbies, and hi[j] is the index of the j-th hobby, which is an integer in [1, 1000].

    +

    +Output Specification: +

    +

    For each case, print in one line the total number of clusters in the network. Then in the second line, print the numbers of people in the clusters in non-increasing order. The numbers must be separated by exactly one space, and there must be no extra space at the end of the line. +

    +Sample Input:
    +8
    +3: 2 7 10
    +1: 4
    +2: 5 3
    +1: 4
    +1: 3
    +1: 4
    +4: 6 8 1 5
    +1: 4
    +
    +Sample Output:
    +3
    +4 3 1
    +
    +
    \ No newline at end of file diff --git a/html/a1108.html b/html/a1108.html new file mode 100644 index 0000000..c55e9d4 --- /dev/null +++ b/html/a1108.html @@ -0,0 +1,36 @@ + + +

    1108. Finding Average (20)

    +
    +

    The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A "legal" input is a real number in [-1000, 1000] and is accurate up to no more than 2 decimal places. When you calculate the average, those illegal numbers must not be counted in.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=100). Then N numbers are given in the next line, separated by one space. +

    +

    +Output Specification: +

    +

    For each illegal input number, print in a line "ERROR: X is not a legal number" where X is the input. Then finally print in a line the result: "The average of K numbers is Y" where K is the number of legal inputs and Y is their average, accurate to 2 decimal places. In case the average cannot be calculated, output "Undefined" instead of Y. In case K is only 1, output "The average of 1 number is Y" instead. +

    +Sample Input 1:
    +7
    +5 -3.2 aaa 9999 2.3.4 7.123 2.35
    +
    +Sample Output 1:
    +ERROR: aaa is not a legal number
    +ERROR: 9999 is not a legal number
    +ERROR: 2.3.4 is not a legal number
    +ERROR: 7.123 is not a legal number
    +The average of 3 numbers is 1.38
    +
    +Sample Input 2:
    +2
    +aaa -9999
    +
    +Sample Output 2:
    +ERROR: aaa is not a legal number
    +ERROR: -9999 is not a legal number
    +The average of 0 numbers is Undefined
    +
    +
    \ No newline at end of file diff --git a/html/a1109.html b/html/a1109.html new file mode 100644 index 0000000..c88a551 --- /dev/null +++ b/html/a1109.html @@ -0,0 +1,41 @@ + + +

    1109. Group Photo (25)

    +
    +

    Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:

    + +

    Now given the information of a group of people, you are supposed to write a program to output their formation.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each test case, the first line contains two positive integers N (<=10000), the total number of people, and K (<=10), the total number of rows. Then N lines follow, each gives the name of a person (no more than 8 English letters without space) and his/her height (an integer in [30, 300]).

    +

    +Output Specification: +

    +

    For each case, print the formation -- that is, print the names of people in K lines. The names must be separated by exactly one space, but there must be no extra space at the end of each line. Note: since you are facing the group, people in the rear rows must be printed above the people in the front rows. +

    +Sample Input:
    +10 3
    +Tom 188
    +Mike 170
    +Eva 168
    +Tim 160
    +Joe 190
    +Ann 168
    +Bob 175
    +Nick 186
    +Amy 160
    +John 159
    +
    +Sample Output:
    +Bob Tom Joe Nick
    +Ann Mike Eva
    +Tim Amy John
    +
    +
    \ No newline at end of file diff --git a/html/a1110.html b/html/a1110.html new file mode 100644 index 0000000..251cc12 --- /dev/null +++ b/html/a1110.html @@ -0,0 +1,44 @@ + + +

    1110. Complete Binary Tree (25)

    +
    +

    Given a tree, you are supposed to tell if it is a complete binary tree.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=20) which is the total number of nodes in the tree -- and hence the nodes are numbered from 0 to N-1. Then N lines follow, each corresponds to a node, and gives the indices of the left and right children of the node. If the child does not exist, a "-" will be put at the position. Any pair of children are separated by a space.

    +

    +Output Specification: +

    +

    For each case, print in one line "YES" and the index of the last node if the tree is a complete binary tree, or "NO" and the index of the root if not. There must be exactly one space separating the word and the number. +

    +Sample Input 1:
    +9
    +7 8
    +- -
    +- -
    +- -
    +0 1
    +2 3
    +4 5
    +- -
    +- -
    +
    +Sample Output 1:
    +YES 8
    +
    +Sample Input 2:
    +8
    +- -
    +4 5
    +0 6
    +- -
    +2 3
    +- 7
    +- -
    +- -
    +
    +Sample Output 2:
    +NO 1
    +
    +
    \ No newline at end of file diff --git a/html/a1111.html b/html/a1111.html new file mode 100644 index 0000000..f4af456 --- /dev/null +++ b/html/a1111.html @@ -0,0 +1,80 @@ + + +

    1111. Online Map (30)

    +
    +

    Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is guaranteed that a path exists for any request. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives two positive integers N (2 <= N <= 500), and M, being the total number of streets intersections on a map, and the number of streets, respectively. Then M lines follow, each describes a street in the format:

    +

    +V1 V2 one-way length time +

    +

    +where V1 and V2 are the indices (from 0 to N-1) of the two ends of the street; one-way is 1 if the street is one-way from V1 to V2, or 0 if not; length is the length of the street; and time is the time taken to pass the street. +

    +

    Finally a pair of source and destination is given.

    +

    +Output Specification: +

    +

    For each case, first print the shortest path from the source to the destination with distance D in the format: +

    +

    +Distance = D: source -> v1 -> ... -> destination +

    +

    +Then in the next line print the fastest path with total time T: +

    +

    +Time = T: source -> w1 -> ... -> destination +

    +

    +In case the shortest path is not unique, output the fastest one among the shortest paths, which is guaranteed to be unique. In case the fastest path is not unique, output the one that passes through the fewest intersections, which is guaranteed to be unique. +

    +

    +In case the shortest and the fastest paths are identical, print them in one line in the format: +

    +

    +Distance = D; Time = T: source -> u1 -> ... -> destination +

    +Sample Input 1:
    +10 15
    +0 1 0 1 1
    +8 0 0 1 1
    +4 8 1 1 1
    +3 4 0 3 2
    +3 9 1 4 1
    +0 6 0 1 1
    +7 5 1 2 1
    +8 5 1 2 1
    +2 3 0 2 2
    +2 1 1 1 1
    +1 3 0 3 1
    +1 4 0 1 1
    +9 7 1 3 1
    +5 1 0 5 2
    +6 5 1 1 2
    +3 5
    +
    +Sample Output 1:
    +Distance = 6: 3 -> 4 -> 8 -> 5
    +Time = 3: 3 -> 1 -> 5
    +
    +Sample Input 2:
    +7 9
    +0 4 1 1 1
    +1 6 1 1 3
    +2 6 1 1 1
    +2 5 1 2 2
    +3 0 0 1 1
    +3 1 1 1 3
    +3 2 1 1 2
    +4 5 0 2 2
    +6 5 1 1 2
    +3 5
    +
    +Sample Output 2:
    +Distance = 3; Time = 4: 3 -> 2 -> 5
    +
    +
    \ No newline at end of file diff --git a/html/a1112.html b/html/a1112.html new file mode 100644 index 0000000..6fc0437 --- /dev/null +++ b/html/a1112.html @@ -0,0 +1,30 @@ + + +

    1112. Stucked Keyboard (20)

    +
    +

    +On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for k times.

    +

    Now given a resulting string on screen, you are supposed to list all the possible stucked keys, and the original string. +

    +

    +Notice that there might be some characters that are typed repeatedly. The stucked key will always repeat output for a fixed k times whenever it is pressed. For example, when k=3, from the string "thiiis iiisss a teeeeeest" we know that the keys "i" and "e" might be stucked, but "s" is not even though it appears repeatedly sometimes. The original string could be "this isss a teest". +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the 1st line gives a positive integer k ( 1<k<=100 ) which is the output repeating times of a stucked key. The 2nd line contains the resulting string on screen, which consists of no more than 1000 characters from {a-z}, {0-9} and "_". It is guaranteed that the string is non-empty.

    +

    +Output Specification: +

    +

    +For each test case, print in one line the possible stucked keys, in the order of being detected. Make sure that each key is printed once only. Then in the next line print the original string. It is guaranteed that there is at least one stucked key. +

    +Sample Input:
    +3
    +caseee1__thiiis_iiisss_a_teeeeeest
    +
    +Sample Output:
    +ei
    +case1__this_isss_a_teest
    +
    +
    \ No newline at end of file diff --git a/html/a1113.html b/html/a1113.html new file mode 100644 index 0000000..32c5c32 --- /dev/null +++ b/html/a1113.html @@ -0,0 +1,30 @@ + + +

    1113. Integer Set Partition (25)

    +
    +

    Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1 and n2 numbers, respectively. Let S1 and S2 denote the sums of all the numbers in A1 and A2, respectively. You are supposed to make the partition so that |n1 - n2| is minimized first, and then |S1 - S2| is maximized. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives an integer N (2 <= N <= 105), and then N positive integers follow in the next line, separated by spaces. It is guaranteed that all the integers and their sum are less than 231.

    +

    +Output Specification: +

    +

    For each case, print in a line two numbers: |n1 - n2| and |S1 - S2|, separated by exactly one space. +

    +Sample Input 1:
    +10
    +23 8 10 99 46 2333 46 1 666 555
    +
    +Sample Output 1:
    +0 3611
    +
    +Sample Input 2:
    +13
    +110 79 218 69 3721 100 29 135 2 6 13 5188 85
    +
    +Sample Output 2:
    +1 9359
    +
    +
    \ No newline at end of file diff --git a/html/a1114.html b/html/a1114.html new file mode 100644 index 0000000..13564fe --- /dev/null +++ b/html/a1114.html @@ -0,0 +1,46 @@ + + +

    1114. Family Property (25)

    +
    +

    This time, you are supposed to help us collect the data for family-owned property. Given each person's family members, and the estate(房产)info under his/her own name, we need to know the size of each family, and the average area and number of sets of their real estate.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=1000). Then N lines follow, each gives the infomation of a person who owns estate in the format:

    +

    +ID Father Mother k Child1 ... Childk M_estate Area +

    +

    +where ID is a unique 4-digit identification number for each person; Father and Mother are the ID's of this person's parents (if a parent has passed away, -1 will be given instead); k (0<=k<=5) is the number of children of this person; Childi's are the ID's of his/her children; M_estate is the total number of sets of the real estate under his/her name; and Area is the total area of his/her estate. +

    +

    +Output Specification: +

    +

    For each case, first print in a line the number of families (all the people that are related directly or indirectly are considered in the same family). Then output the family info in the format: +

    +

    +ID M AVG_sets AVG_area +

    +

    +where ID is the smallest ID in the family; M is the total number of family members; AVG_sets is the average number of sets of their real estate; and AVG_area is the average area. The average numbers must be accurate up to 3 decimal places. The families must be given in descending order of their average areas, and in ascending order of the ID's if there is a tie. +

    +Sample Input:
    +10
    +6666 5551 5552 1 7777 1 100
    +1234 5678 9012 1 0002 2 300
    +8888 -1 -1 0 1 1000
    +2468 0001 0004 1 2222 1 500
    +7777 6666 -1 0 2 300
    +3721 -1 -1 1 2333 2 150
    +9012 -1 -1 3 1236 1235 1234 1 100
    +1235 5678 9012 0 1 50
    +2222 1236 2468 2 6661 6662 1 300
    +2333 -1 3721 3 6661 6662 6663 1 100
    +
    +Sample Output:
    +3
    +8888 1 1.000 1000.000
    +0001 15 0.600 100.000
    +5551 4 0.750 100.000
    +
    +
    \ No newline at end of file diff --git a/html/a1115.html b/html/a1115.html new file mode 100644 index 0000000..6c9bd4f --- /dev/null +++ b/html/a1115.html @@ -0,0 +1,32 @@ + + +

    1115. Counting Nodes in a BST (30)

    +
    +

    A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:

    + +

    Insert a sequence of numbers into an initially empty binary search tree. Then you are supposed to count the total number of nodes in the lowest 2 levels of the resulting tree.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=1000) which is the size of the input sequence. Then given in the next line are the N integers in [-1000 1000] which are supposed to be inserted into an initially empty binary search tree.

    +

    +Output Specification: +

    +

    For each case, print in one line the numbers of nodes in the lowest 2 levels of the resulting tree in the format:

    +

    +n1 + n2 = n +

    +

    +where n1 is the number of nodes in the lowest level, n2 is that of the level above, and n is the sum. +

    +Sample Input:
    +9
    +25 30 42 16 20 20 35 -5 28
    +
    +Sample Output:
    +2 + 4 = 6
    +
    +
    \ No newline at end of file diff --git a/html/a1116.html b/html/a1116.html new file mode 100644 index 0000000..0c07222 --- /dev/null +++ b/html/a1116.html @@ -0,0 +1,46 @@ + + +

    1116. Come on! Let's C (20)

    +
    +

    "Let's C" is a popular and fun programming contest hosted by the College of Computer Science and Technology, Zhejiang University. Since the idea of the contest is for fun, the award rules are funny as the following:

    +

    +0. The Champion will receive a "Mystery Award" (such as a BIG collection of students' research papers...).
    +1. Those who ranked as a prime number will receive the best award -- the Minions (小黄人)!
    +2. Everyone else will receive chocolates. +

    +

    Given the final ranklist and a sequence of contestant ID's, you are supposed to tell the corresponding awards. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=10000), the total number of contestants. Then N lines of the ranklist follow, each in order gives a contestant's ID (a 4-digit number). After the ranklist, there is a positive integer K followed by K query ID's.

    +

    +Output Specification: +

    +

    For each query, print in a line "ID: award" where the award is "Mystery Award", or "Minion", or "Chocolate". If the ID is not in the ranklist, print "Are you kidding?" instead. If the ID has been checked before, print "ID: Checked". +

    +Sample Input:
    +6
    +1111
    +6666
    +8888
    +1234
    +5555
    +0001
    +6
    +8888
    +0001
    +1111
    +2222
    +8888
    +2222
    +
    +Sample Output:
    +8888: Minion
    +0001: Chocolate
    +1111: Mystery Award
    +2222: Are you kidding?
    +8888: Checked
    +2222: Are you kidding?
    +
    +
    \ No newline at end of file diff --git a/html/a1117.html b/html/a1117.html new file mode 100644 index 0000000..dc8ff06 --- /dev/null +++ b/html/a1117.html @@ -0,0 +1,25 @@ + + +

    1117. Eddington Number(25)

    +
    +

    British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, he has even defined an "Eddington number", E -- that is, the maximum integer E such that it is for E days that one rides more than E miles. Eddington's own E was 87.

    +

    +Now given everyday's distances that one rides for N days, you are supposed to find the corresponding E (<=N). +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N(<=105), the days of continuous riding. Then N non-negative integers are given in the next line, being the riding distances of everyday.

    +

    +Output Specification: +

    +

    For each case, print in a line the Eddington number for these N days. +

    +Sample Input:
    +10
    +6 7 6 9 3 10 8 2 7 8
    +
    +Sample Output:
    +6
    +
    +
    \ No newline at end of file diff --git a/html/a1118.html b/html/a1118.html new file mode 100644 index 0000000..2637622 --- /dev/null +++ b/html/a1118.html @@ -0,0 +1,36 @@ + + +

    1118. Birds in Forest (25)

    +
    +

    Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of trees in the forest, and for any pair of birds, tell if they are on the same tree. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains a positive number N (<= 104) which is the number of pictures. Then N lines follow, each describes a picture in the format:
    +K B1 B2 ... BK
    +where K is the number of birds in this picture, and Bi's are the indices of birds. It is guaranteed that the birds in all the pictures are numbered continuously from 1 to some number that is no more than 104.

    +

    +After the pictures there is a positive number Q (<= 104) which is the number of queries. Then Q lines follow, each contains the indices of two birds. +

    +

    +Output Specification: +

    +

    For each test case, first output in a line the maximum possible number of trees and the number of birds. +Then for each query, print in a line "Yes" if the two birds belong to the same tree, or "No" if not.

    +Sample Input:
    +4
    +3 10 1 2
    +2 3 4
    +4 1 5 7 8
    +3 9 6 4
    +2
    +10 5
    +3 7
    +
    +Sample Output:
    +2 10
    +Yes
    +No
    +
    +
    \ No newline at end of file diff --git a/html/a1119.html b/html/a1119.html new file mode 100644 index 0000000..8a91031 --- /dev/null +++ b/html/a1119.html @@ -0,0 +1,33 @@ + + +

    1119. Pre- and Post-order Traversals (30)

    +
    +

    Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences, or preorder and inorder traversal sequences. However, if only the postorder and preorder traversal sequences are given, the corresponding tree may no longer be unique.

    +

    Now given a pair of postorder and preorder traversal sequences, you are supposed to output the corresponding inorder traversal sequence of the tree. If the tree is not unique, simply output any one of them.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=30), the total number of nodes in the binary tree. The second line gives the preorder sequence and the third line gives the postorder sequence. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, first printf in a line "Yes" if the tree is unique, or "No" if not. Then print in the next line the inorder traversal sequence of the corresponding binary tree. If the solution is not unique, any answer would do. It is guaranteed that at least one solution exists. All the numbers in a line must be separated by exactly one space, and there must be no extra space at the end of the line.

    +Sample Input 1:
    +7
    +1 2 3 4 6 7 5
    +2 6 7 4 5 3 1
    +
    +Sample Output 1:
    +Yes
    +2 1 6 4 7 3 5
    +
    +Sample Input 2:
    +4
    +1 2 3 4
    +2 4 3 1
    +
    +Sample Output 2:
    +No
    +2 1 3 4
    +
    +
    \ No newline at end of file diff --git a/html/a1120.html b/html/a1120.html new file mode 100644 index 0000000..028ba48 --- /dev/null +++ b/html/a1120.html @@ -0,0 +1,23 @@ + + +

    1120. Friend Numbers (20)

    +
    +

    Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend ID. Given some numbers, you are supposed to count the number of different friend ID's among them. Note: a number is considered a friend of itself.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N. Then N positive integers are given in the next line, separated by spaces. All the numbers are less than 104.

    +

    +Output Specification: +

    +

    For each case, print in the first line the number of different frind ID's among the given integers. Then in the second line, output the friend ID's in increasing order. The numbers must be separated by exactly one space and there must be no extra space at the end of the line. +

    +Sample Input:
    +8
    +123 899 51 998 27 33 36 12
    +
    +Sample Output:
    +4
    +3 6 9 26
    +
    +
    \ No newline at end of file diff --git a/html/a1121.html b/html/a1121.html new file mode 100644 index 0000000..5b029f8 --- /dev/null +++ b/html/a1121.html @@ -0,0 +1,27 @@ + + +

    1121. Damn Single (25)

    +
    +

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=50000), the total number of couples. Then N lines of the couples follow, each gives a couple of ID's which are 5-digit numbers (i.e. from 00000 to 99999). After the list of couples, there is a positive integer M (<=10000) followed by M ID's of the party guests. The numbers are separated by spaces. It is guaranteed that nobody is having bigamous marriage (重婚) or dangling with more than one companion.

    +

    +Output Specification: +

    +

    First print in a line the total number of lonely guests. Then in the next line, print their ID's in increasing order. The numbers must be separated by exactly 1 space, and there must be no extra space at the end of the line. +

    +Sample Input:
    +3
    +11111 22222
    +33333 44444
    +55555 66666
    +7
    +55555 44444 10000 88888 22222 11111 23333
    +
    +Sample Output:
    +5
    +10000 23333 44444 55555 88888
    +
    +
    \ No newline at end of file diff --git a/html/a1122.html b/html/a1122.html new file mode 100644 index 0000000..f152a26 --- /dev/null +++ b/html/a1122.html @@ -0,0 +1,52 @@ + + +

    1122. Hamiltonian Cycle (25)

    +
    +

    The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a graph. Such a cycle is called a "Hamiltonian cycle". +

    +

    In this problem, you are supposed to tell if a given cycle is a Hamiltonian cycle. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains 2 positive integers N (2< N <= 200), the number of vertices, and M, the number of edges in an undirected graph. Then M lines follow, each describes an edge in the format "Vertex1 Vertex2", where the vertices are numbered from 1 to N. The next line gives a positive integer K which is the number of queries, followed by K lines of queries, each in the format:

    +

    +n V1 V2 ... Vn +

    +

    +where n is the number of vertices in the list, and Vi's are the vertices on a path. +

    +

    +Output Specification: +

    +

    For each query, print in a line "YES" if the path does form a Hamiltonian cycle, or "NO" if not. +

    +Sample Input:
    +6 10
    +6 2
    +3 4
    +1 5
    +2 5
    +3 1
    +4 1
    +1 6
    +6 3
    +1 2
    +4 5
    +6
    +7 5 1 4 3 6 2 5
    +6 5 1 4 3 6 2
    +9 6 2 1 6 3 4 5 2 6
    +4 1 2 5 1
    +7 6 1 3 4 5 2 6
    +7 6 1 2 5 4 3 1
    +
    +Sample Output:
    +YES
    +NO
    +NO
    +NO
    +YES
    +NO
    +
    +
    \ No newline at end of file diff --git a/html/a1123.html b/html/a1123.html new file mode 100644 index 0000000..5ee2327 --- /dev/null +++ b/html/a1123.html @@ -0,0 +1,35 @@ + + +

    1123. Is It a Complete AVL Tree (30)

    +
    +

    An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. Figures 1-4 illustrate the rotation rules.

    +
        
    +

    +
        
    +

    Now given a sequence of insertions, you are supposed to output the level-order traversal sequence of the resulting AVL tree, and to tell if it is a complete binary tree.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains a positive integer N (<= 20). Then N distinct integer keys are given in the next line. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, insert the keys one by one into an initially empty AVL tree. Then first print in a line the level-order traversal sequence of the resulting AVL tree. All the numbers in a line must be separated by a space, and there must be no extra space at the end of the line. Then in the next line, print "YES" if the tree is complete, or "NO" if not. +

    +Sample Input 1:
    +5
    +88 70 61 63 65
    +
    +Sample Output 1:
    +70 63 88 61 65
    +YES
    +
    +Sample Input 2:
    +8
    +88 70 61 96 120 90 65 68
    +
    +Sample Output 2:
    +88 65 96 61 70 90 120 68
    +NO
    +
    +
    \ No newline at end of file diff --git a/html/a1124.html b/html/a1124.html new file mode 100644 index 0000000..6c7c59c --- /dev/null +++ b/html/a1124.html @@ -0,0 +1,41 @@ + + +

    1124. Raffle for Weibo Followers (20)

    +
    +

    John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo -- that is, he would select winners from every N followers who forwarded his post, and give away gifts. Now you are supposed to help him generate the list of winners.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives three positive integers M (<= 1000), N and S, being the total number of forwards, the skip number of winners, and the index of the first winner (the indices start from 1). Then M lines follow, each gives the nickname (a nonempty string of no more than 20 characters, with no white space or return) of a follower who has forwarded John's post.

    +

    Note: it is possible that someone would forward more than once, but no one can win more than once. Hence if the current candidate of a winner has won before, we must skip him/her and consider the next one.

    +

    +Output Specification: +

    +

    For each case, print the list of winners in the same order as in the input, each nickname occupies a line. If there is no winner yet, print "Keep going..." instead. +

    +Sample Input 1:
    +9 3 2
    +Imgonnawin!
    +PickMe
    +PickMeMeMeee
    +LookHere
    +Imgonnawin!
    +TryAgainAgain
    +TryAgainAgain
    +Imgonnawin!
    +TryAgainAgain
    +
    +Sample Output 1:
    +PickMe
    +Imgonnawin!
    +TryAgainAgain
    +
    +Sample Input 2:
    +2 3 5
    +Imgonnawin!
    +PickMe
    +
    +Sample Output 2:
    +Keep going...
    +
    +
    \ No newline at end of file diff --git a/html/a1125.html b/html/a1125.html new file mode 100644 index 0000000..74d3903 --- /dev/null +++ b/html/a1125.html @@ -0,0 +1,28 @@ + + +

    1125. Chain the Ropes (25)

    +
    +

    Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fold two segments into loops and chain them into one piece, as shown by the figure. The resulting chain will be treated as another segment of rope and can be folded again. After each chaining, the lengths of the original two segments will be halved. +

    +
    +

    +Your job is to make the longest possible rope out of N given segments. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (2 <= N <= 104). Then N positive integer lengths of the segments are given in the next line, separated by spaces. All the integers are no more than 104. +

    +

    +Output Specification: +

    +

    For each case, print in a line the length of the longest possible rope that can be made by the given segments. The result must be rounded to the nearest integer that is no greater than the maximum length. +

    +Sample Input:
    +8
    +10 15 12 3 4 13 1 15
    +
    +Sample Output:
    +14
    +
    +
    \ No newline at end of file diff --git a/html/a1126.html b/html/a1126.html new file mode 100644 index 0000000..17fb524 --- /dev/null +++ b/html/a1126.html @@ -0,0 +1,66 @@ + + +

    1126. Eulerian Path (25)

    +
    +

    In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were first discussed by Leonhard Euler while solving the famous Seven Bridges of Konigsberg problem in 1736. It has been proven that connected graphs with all vertices of even degree have an Eulerian circuit, and such graphs are called Eulerian. If there are exactly two vertices of odd degree, all Eulerian paths start at one of them and end at the other. A graph that has an Eulerian path but not an Eulerian circuit is called semi-Eulerian. (Cited from https://en.wikipedia.org/wiki/Eulerian_path) +

    +

    +Given an undirected graph, you are supposed to tell if it is Eulerian, semi-Eulerian, or non-Eulerian. +

    +

    Input Specification:

    +

    Each input file contains one test case. Each case starts with a line containing 2 numbers N (<= 500), and M, which are the total number of vertices, and the number of edges, respectively. Then M lines follow, each describes an edge by giving the two ends of the edge (the vertices are numbered from 1 to N).

    +

    Output Specification:

    +

    For each test case, first print in a line the degrees of the vertices in ascending order of their indices. Then in the next line print your conclusion about the graph -- either "Eulerian", "Semi-Eulerian", or "Non-Eulerian". Note that all the numbers in the first line must be separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line. +

    +Sample Input 1:
    +7 12
    +5 7
    +1 2
    +1 3
    +2 3
    +2 4
    +3 4
    +5 2
    +7 6
    +6 3
    +4 5
    +6 4
    +5 6
    +
    +Sample Output 1:
    +2 4 4 4 4 4 2
    +Eulerian
    +
    +Sample Input 2:
    +6 10
    +1 2
    +1 3
    +2 3
    +2 4
    +3 4
    +5 2
    +6 3
    +4 5
    +6 4
    +5 6
    +
    +Sample Output 2:
    +2 4 4 4 3 3
    +Semi-Eulerian
    +
    +Sample Input 3:
    +5 8
    +1 2
    +2 5
    +5 4
    +4 1
    +1 3
    +3 2
    +3 4
    +5 3
    +
    +Sample Output 3:
    +3 3 4 3 3
    +Non-Eulerian
    +
    +
    \ No newline at end of file diff --git a/html/a1127.html b/html/a1127.html new file mode 100644 index 0000000..b15cee0 --- /dev/null +++ b/html/a1127.html @@ -0,0 +1,23 @@ + + +

    1127. ZigZagging on a Tree (30)

    +
    +

    Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences. And it is a simple standard routine to print the numbers in level-order. However, if you think the problem is too simple, then you are too naive. This time you are supposed to print the numbers in "zigzagging order" -- that is, starting from the root, print the numbers level-by-level, alternating between left to right and right to left. For example, for the following tree you must output: 1 11 5 8 17 12 20 15.

    +
    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<= 30), the total number of nodes in the binary tree. The second line gives the inorder sequence and the third line gives the postorder sequence. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print the zigzagging sequence of the tree in a line. All the numbers in a line must be separated by exactly one space, and there must be no extra space at the end of the line.

    +Sample Input:
    +8
    +12 11 20 17 1 15 8 5
    +12 20 17 11 15 8 5 1
    +
    +Sample Output:
    +1 11 5 8 17 12 20 15
    +
    +
    \ No newline at end of file diff --git a/html/a1128.html b/html/a1128.html new file mode 100644 index 0000000..cc34e80 --- /dev/null +++ b/html/a1128.html @@ -0,0 +1,43 @@ + + +

    1128. N Queens Puzzle (20)

    +
    +

    The "eight queens puzzle" is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagonal. The eight queens puzzle is an example of the more general N queens problem of placing N non-attacking queens on an N×N chessboard. (From Wikipedia - "Eight queens puzzle".)

    +

    Here you are NOT asked to solve the puzzles. Instead, you are supposed to judge whether or not a given configuration of the chessboard is a solution. To simplify the representation of a chessboard, let us assume that no two queens will be placed in the same column. Then a configuration can be represented by a simple integer sequence (Q1, Q2, ..., QN), where Qi is the row number of the queen in the i-th column. For example, Figure 1 can be represented by (4, 6, 8, 2, 7, 1, 3, 5) and it is indeed a solution to the 8 queens puzzle; while Figure 2 can be represented by (4, 6, 7, 2, 8, 1, 9, 5, 3) and is NOT a 9 queens' solution.

    +
    + + + + + + + + + + + +
      
    Figure 1
      
    Figure 2
    +
    +

    +Input Specification: +

    +

    Each input file contains several test cases. The first line gives an integer K (1 < K <= 200). Then K lines follow, each gives a configuration in the format "N Q1 Q2 ... QN", where 4 <= N <= 1000 and it is guaranteed that 1 <= Qi <= N for all i=1, ..., N. The numbers are separated by spaces.

    +

    +Output Specification: +

    +

    For each configuration, if it is a solution to the N queens problem, print "YES" in a line; or "NO" if not. +

    +Sample Input:
    +4
    +8 4 6 8 2 7 1 3 5
    +9 4 6 7 2 8 1 9 5 3
    +6 1 5 2 6 4 3
    +5 1 3 5 2 4
    +
    +Sample Output:
    +YES
    +NO
    +NO
    +YES
    +
    +
    \ No newline at end of file diff --git a/html/a1129.html b/html/a1129.html new file mode 100644 index 0000000..85bf79f --- /dev/null +++ b/html/a1129.html @@ -0,0 +1,39 @@ + + +

    1129. Recommendation System (25)

    +
    +

    Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user's preference by the number of times that an item has been accessed by this user.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each test case, the first line contains two positive integers: N (<= 50000), the total number of queries, and K (<= 10), the maximum number of recommendations the system must show to the user. Then given in the second line are the indices of items that the user is accessing -- for the sake of simplicity, all the items are indexed from 1 to N. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each case, process the queries one by one. Output the recommendations for each query in a line in the format:

    +

    +query: rec[1] rec[2] ... rec[K] +

    +

    +where query is the item that the user is accessing, and rec[i] (i = 1, ... K) is the i-th item that the system recommends to the user. The first K items that have been accessed most frequently are supposed to be recommended in non-increasing order of their frequencies. If there is a tie, the items will be ordered by their indices in increasing order.

    +

    +Note: there is no output for the first item since it is impossible to give any recommendation at the time. It is guaranteed to have the output for at least one query. +

    +Sample Input:
    +12 3
    +3 5 7 5 5 3 2 1 8 3 8 12
    +
    +Sample Output:
    +5: 3
    +7: 3 5
    +5: 3 5 7
    +5: 5 3 7
    +3: 5 3 7
    +2: 5 3 7
    +1: 5 3 2
    +8: 5 3 1
    +3: 5 3 1
    +8: 3 5 1
    +12: 3 5 8
    +
    +
    \ No newline at end of file diff --git a/html/a1130.html b/html/a1130.html new file mode 100644 index 0000000..967e0ae --- /dev/null +++ b/html/a1130.html @@ -0,0 +1,61 @@ + + +

    1130. Infix Expression (25)

    +
    +

    Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with parentheses reflecting the precedences of the operators. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N ( <= 20 ) which is the total number of nodes in the syntax tree. Then N lines follow, each gives the information of a node (the i-th line corresponds to the i-th node) in the format: +

    +

    +data left_child right_child +

    +

    +where data is a string of no more than 10 characters, left_child and right_child are the indices of this node's left and right children, respectively. The nodes are indexed from 1 to N. The NULL link is represented by -1. The figures 1 and 2 correspond to the samples 1 and 2, respectively. +

    + + + + + + + + + +
    Figure 1
    Figure 2
    +

    +Output Specification: +

    +

    For each case, print in a line the infix expression, with parentheses reflecting the precedences of the operators. Note that there must be no extra parentheses for the final expression, as is shown by the samples. There must be no space between any symbols. +

    +Sample Input 1:
    +8
    +* 8 7
    +a -1 -1
    +* 4 1
    ++ 2 5
    +b -1 -1
    +d -1 -1
    +- -1 6
    +c -1 -1
    +
    +Sample Output 1:
    +(a+b)*(c*(-d))
    +
    +Sample Input 2:
    +8
    +2.35 -1 -1
    +* 6 1
    +- -1 4
    +% 7 8
    ++ 2 3
    +a -1 -1
    +str -1 -1
    +871 -1 -1
    +
    +Sample Output 2:
    +(a*2.35)+(-(str%871))
    +
    +
    \ No newline at end of file diff --git a/html/a1131.html b/html/a1131.html new file mode 100644 index 0000000..7e6055a --- /dev/null +++ b/html/a1131.html @@ -0,0 +1,68 @@ + + +

    1131. Subway Map (30)

    +
    +

    In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with your computer skills! Given the starting position of your user, your task is to find the quickest way to his/her destination.

    +
    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains a positive integer N (< =100), the number of subway lines. Then N lines follow, with the i-th (i = 1, ..., N) line describes the i-th subway line in the format:

    +

    +M S[1] S[2] ... S[M] +

    +

    +where M (<= 100) is the number of stops, and S[i]'s (i = 1, ... M) are the indices of the stations (the indices are 4-digit numbers from 0000 to 9999) along the line. It is guaranteed that the stations are given in the correct order -- that is, the train travels between S[i] and S[i+1] (i = 1, ..., M-1) without any stop.

    +

    +Note: It is possible to have loops, but not self-loop (no train starts from S and stops at S without passing through another station). Each station interval belongs to a unique subway line. Although the lines may cross each other at some stations (so called "transfer stations"), no station can be the conjunction of more than 5 lines. +

    +

    +After the description of the subway, another positive integer K (<= 10) is given. Then K lines follow, each gives a query from your user: the two indices as the starting station and the destination, respectively. +

    +

    +The following figure shows the sample map. +

    +
    +

    +Note: It is guaranteed that all the stations are reachable, and all the queries consist of legal station numbers. +

    +

    +Output Specification: +

    +

    For each query, first print in a line the minimum number of stops. Then you are supposed to show the optimal path in a friendly format as the following: +

    +
    +Take Line#X1 from S1 to S2.
    +Take Line#X2 from S2 to S3.
    +......
    +
    +

    +where Xi's are the line numbers and Si's are the station indices. Note: Besides the starting and ending stations, only the transfer stations shall be printed. +

    +

    +If the quickest path is not unique, output the one with the minimum number of transfers, which is guaranteed to be unique. +

    +Sample Input:
    +4
    +7 1001 3212 1003 1204 1005 1306 7797
    +9 9988 2333 1204 2006 2005 2004 2003 2302 2001
    +13 3011 3812 3013 3001 1306 3003 2333 3066 3212 3008 2302 3010 3011
    +4 6666 8432 4011 1306
    +3
    +3011 3013
    +6666 2001
    +2004 3001
    +
    +Sample Output:
    +2
    +Take Line#3 from 3011 to 3013.
    +10
    +Take Line#4 from 6666 to 1306.
    +Take Line#3 from 1306 to 2302.
    +Take Line#2 from 2302 to 2001.
    +6
    +Take Line#2 from 2004 to 1204.
    +Take Line#1 from 1204 to 1306.
    +Take Line#3 from 1306 to 3001.
    +
    +
    \ No newline at end of file diff --git a/html/a1132.html b/html/a1132.html new file mode 100644 index 0000000..f51b602 --- /dev/null +++ b/html/a1132.html @@ -0,0 +1,26 @@ + + +

    1132. Cut Integer (20)

    +
    +

    Cutting an integer means to cut a K digits long integer Z into two integers of (K/2) digits long integers A and B. For example, after cutting Z = 167334, we have A = 167 and B = 334. It is interesting to see that Z can be devided by the product of A and B, as 167334 / (167 x 334) = 3. Given an integer Z, you are supposed to test if it is such an integer. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<= 20). Then N lines follow, each gives an integer Z (10<=Z<=231). It is guaranteed that the number of digits of Z is an even number.

    +

    +Output Specification: +

    +

    For each case, print a single line "Yes" if it is such a number, or "No" if not.

    +Sample Input:
    +3
    +167334
    +2333
    +12345678
    +
    +Sample Output:
    +Yes
    +No
    +No
    +
    +
    \ No newline at end of file diff --git a/html/a1133.html b/html/a1133.html new file mode 100644 index 0000000..783423f --- /dev/null +++ b/html/a1133.html @@ -0,0 +1,41 @@ + + +

    1133. Splitting A Linked List (25)

    +
    +

    Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-negatives, and all the values in [0, K] appear before all those greater than K. The order of the elements inside each class must not be changed. For example, given the list being 18→7→-4→0→5→-6→10→11→-2 and K being 10, you must output -4→-6→-2→7→0→5→10→18→11.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (<= 105) which is the total number of nodes, and a positive K (<=1000). The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

    +

    Then N lines follow, each describes a node in the format:

    +

    Address Data Next

    +

    where Address is the position of the node, Data is an integer in [-105, 105], and Next is the position of the next node. It is guaranteed that the list is not empty.

    +

    +Output Specification: +

    +

    For each case, output in order (from beginning to the end of the list) the resulting linked list. Each node occupies a line, and is printed in the same format as in the input. +

    +Sample Input:
    +00100 9 10
    +23333 10 27777
    +00000 0 99999
    +00100 18 12309
    +68237 -6 23333
    +33218 -4 00000
    +48652 -2 -1
    +99999 5 68237
    +27777 11 48652
    +12309 7 33218
    +
    +Sample Output:
    +33218 -4 68237
    +68237 -6 48652
    +48652 -2 12309
    +12309 7 00000
    +00000 0 99999
    +99999 5 23333
    +23333 10 00100
    +00100 18 27777
    +27777 11 -1
    +
    +
    \ No newline at end of file diff --git a/html/a1134.html b/html/a1134.html new file mode 100644 index 0000000..8db16b4 --- /dev/null +++ b/html/a1134.html @@ -0,0 +1,51 @@ + + +

    1134. Vertex Cover (25)

    +
    +

    A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set. Now given a graph with several vertex sets, you are supposed to tell if each of them is a vertex cover or not. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives two positive integers N and M (both no more than 104), being the total numbers of vertices and the edges, respectively. Then M lines follow, each describes an edge by giving the indices (from 0 to N-1) of the two ends of the edge. +

    +

    After the graph, a positive integer K (<= 100) is given, which is the number of queries. Then K lines of queries follow, each in the format:

    +

    +Nv v[1] v[2] ... v[Nv] +

    +

    +where Nv is the number of vertices in the set, and v[i]'s are the indices of the vertices. +

    +

    +Output Specification: +

    +

    For each query, print in a line "Yes" if the set is a vertex cover, or "No" if not. +

    +Sample Input:
    +10 11
    +8 7
    +6 8
    +4 5
    +8 4
    +8 1
    +1 2
    +1 4
    +9 8
    +9 1
    +1 0
    +2 4
    +5
    +4 0 3 8 4
    +6 6 1 7 5 4 9
    +3 1 8 4
    +2 2 8
    +7 9 8 7 6 5 4 2
    +
    +Sample Output:
    +No
    +Yes
    +Yes
    +No
    +No
    +
    +
    \ No newline at end of file diff --git a/html/a1135.html b/html/a1135.html new file mode 100644 index 0000000..c7c5e5a --- /dev/null +++ b/html/a1135.html @@ -0,0 +1,51 @@ + + +

    1135. Is It A Red-Black Tree (30)

    +
    +

    There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties:

    +

    +(1) Every node is either red or black.
    +(2) The root is black.
    +(3) Every leaf (NULL) is black.
    +(4) If a node is red, then both its children are black.
    +(5) For each node, all simple paths from the node to descendant leaves contain the same number of black nodes. +

    +

    For example, the tree in Figure 1 is a red-black tree, while the ones in Figure 2 and 3 are not.

    +
    + + + + + + + + + + + +
    Figure 1
    Figure 2
    Figure 3
    +
    +

    For each given binary search tree, you are supposed to tell if it is a legal red-black tree.

    +

    +Input Specification: +

    +

    Each input file contains several test cases. The first line gives a positive integer K (<=30) which is the total number of cases. For each case, the first line gives a positive integer N (<=30), the total number of nodes in the binary tree. The second line gives the preorder traversal sequence of the tree. While all the keys in a tree are positive integers, we use negative signs to represent red nodes. All the numbers in a line are separated by a space. The sample input cases correspond to the trees shown in Figure 1, 2 and 3.

    +

    +Output Specification: +

    +

    For each test case, print in a line "Yes" if the given tree is a red-black tree, or "No" if not.

    +Sample Input:
    +3
    +9
    +7 -2 1 5 -4 -11 8 14 -15
    +9
    +11 -2 1 -7 5 -4 8 14 -15
    +8
    +10 -7 5 -6 8 15 -11 17
    +
    +Sample Output:
    +Yes
    +No
    +No
    +
    +
    \ No newline at end of file diff --git a/html/a1136.html b/html/a1136.html new file mode 100644 index 0000000..7aab964 --- /dev/null +++ b/html/a1136.html @@ -0,0 +1,50 @@ + + +

    1136. A Delayed Palindrome (20)

    +
    +

    Consider a positive integer N written in standard notation with k+1 digits ai as ak...a1a0 with 0 <= ai < 10 for all i and ak > 0. Then N is palindromic if and only if ai = ak-i for all i. Zero is written 0 and is also palindromic by definition. +

    +

    +Non-palindromic numbers can be paired with palindromic ones via a series of operations. First, the non-palindromic number is reversed and the result is added to the original number. If the result is not a palindromic number, this is repeated until it gives a palindromic number. Such number is called a delayed palindrome. (Quoted from https://en.wikipedia.org/wiki/Palindromic_number) +

    +

    +Given any positive integer, you are supposed to find its paired palindromic number. +

    +

    +Input Specification: +

    +

    Each input file contains one test case which gives a positive integer no more than 1000 digits.

    +

    +Output Specification: +

    +

    For each test case, print line by line the process of finding the palindromic number. The format of each line is the following:

    +A + B = C
    +
    +

    +where A is the original number, B is the reversed A, and C is their sum. A starts being the input number, and this process ends until C becomes a palindromic number -- in this case we print in the last line "C is a palindromic number."; or if a palindromic number cannot be found in 10 iterations, print "Not found in 10 iterations." instead. +

    +Sample Input 1:
    +97152
    +
    +Sample Output 1:
    +97152 + 25179 = 122331
    +122331 + 133221 = 255552
    +255552 is a palindromic number.
    +
    +Sample Input 2:
    +196
    +
    +Sample Output 2:
    +196 + 691 = 887
    +887 + 788 = 1675
    +1675 + 5761 = 7436
    +7436 + 6347 = 13783
    +13783 + 38731 = 52514
    +52514 + 41525 = 94039
    +94039 + 93049 = 187088
    +187088 + 880781 = 1067869
    +1067869 + 9687601 = 10755470
    +10755470 + 07455701 = 18211171
    +Not found in 10 iterations.
    +
    +
    \ No newline at end of file diff --git a/html/a1137.html b/html/a1137.html new file mode 100644 index 0000000..1fb3b27 --- /dev/null +++ b/html/a1137.html @@ -0,0 +1,52 @@ + + +

    1137. Final Grading (25)

    +
    +

    For a student taking the online course "Data Structures" on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from the online programming assignments, and then receive a final grade no less than 60 out of 100. The final grade is calculated by G = (Gmid-termx 40% + Gfinalx 60%) if Gmid-term > Gfinal, or Gfinal will be taken as the final grade G. Here Gmid-term and Gfinal are the student's scores of the mid-term and the final exams, respectively.

    +

    +The problem is that different exams have different grading sheets. Your job is to write a program to merge all the grading sheets into one. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives three positive integers: P , the number of students having done the online programming assignments; M, the number of students on the mid-term list; and N, the number of students on the final exam list. All the numbers are no more than 10,000.

    +

    Then three blocks follow. The first block contains P online programming scores Gp's; the second one contains M mid-term scores Gmid-term's; and the last one contains N final exam scores Gfinal's. Each score occupies a line with the format: StudentID Score, where StudentID is a string of no more than 20 English letters and digits, and Score is a nonnegative integer (the maximum score of the online programming is 900, and that of the mid-term and final exams is 100).

    +

    +Output Specification: +

    +

    For each case, print the list of students who are qualified for certificates. Each student occupies a line with the format: +

    +

    +StudentID Gp Gmid-term Gfinal G +

    +

    +If some score does not exist, output "-1" instead. The output must be sorted in descending order of their final grades (G must be rounded up to an integer). If there is a tie, output in ascending order of their StudentID's. It is guaranteed that the StudentID's are all distinct, and there is at least one qualified student.

    +Sample Input:
    +6 6 7
    +01234 880
    +a1903 199
    +ydjh2 200
    +wehu8 300
    +dx86w 220
    +missing 400
    +ydhfu77 99
    +wehu8 55
    +ydjh2 98
    +dx86w 88
    +a1903 86
    +01234 39
    +ydhfu77 88
    +a1903 66
    +01234 58
    +wehu8 84
    +ydjh2 82
    +missing 99
    +dx86w 81
    +
    +Sample Output:
    +missing 400 -1 99 99
    +ydjh2 200 98 82 88
    +dx86w 220 88 81 84
    +wehu8 300 55 84 84
    +
    +
    \ No newline at end of file diff --git a/html/a1138.html b/html/a1138.html new file mode 100644 index 0000000..b861432 --- /dev/null +++ b/html/a1138.html @@ -0,0 +1,24 @@ + + +

    1138. Postorder Traversal (25)

    +
    +

    Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal sequence of the corresponding binary tree. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=50000), the total number of nodes in the binary tree. The second line gives the preorder sequence and the third line gives the inorder sequence. All the numbers in a line are separated by a space.

    +

    +Output Specification: +

    +

    For each test case, print in one line the first number of the postorder traversal sequence of the corresponding binary tree. +

    +Sample Input:
    +7
    +1 2 3 4 5 6 7
    +2 3 1 5 4 7 6
    +
    +Sample Output:
    +3
    +
    +
    \ No newline at end of file diff --git a/html/a1139.html b/html/a1139.html new file mode 100644 index 0000000..68e6c41 --- /dev/null +++ b/html/a1139.html @@ -0,0 +1,71 @@ + + +

    1139. First Contact (30)

    +
    +

    Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle in the early years. When a boy A had a crush on a girl B, he would usually not contact her directly in the first place. Instead, he might ask another boy C, one of his close friends, to ask another girl D, who was a friend of both B and C, to send a message to B -- quite a long shot, isn't it? Girls would do analogously. +

    +

    +Here given a network of friendship relations, you are supposed to help a boy or a girl to list all their friends who can possibly help them making the first contact. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives two positive integers N (1 < N <= 300) and M, being the total number of people and the number of friendship relations, respectively. Then M lines follow, each gives a pair of friends. Here a person is represented by a 4-digit ID. To tell their genders, we use a negative sign to represent girls. +

    +

    After the relations, a positive integer K (<= 100) is given, which is the number of queries. Then K lines of queries follow, each gives a pair of lovers, separated by a space. It is assumed that the first one is having a crush on the second one. +

    +

    +Output Specification: +

    +

    For each query, first print in a line the number of different pairs of friends they can find to help them, then in each line print the IDs of a pair of friends. +

    +

    +If the lovers A and B are of opposite genders, you must first print the friend of A who is of the same gender of A, then the friend of B, who is of the same gender of B. If they are of the same gender, then both friends must be in the same gender as theirs. It is guaranteed that each person has only one gender. +

    +

    +The friends must be printed in non-decreasing order of the first IDs, and for the same first ones, in increasing order of the seconds ones. +

    +Sample Input:
    +10 18
    +-2001 1001
    +-2002 -2001
    +1004 1001
    +-2004 -2001
    +-2003 1005
    +1005 -2001
    +1001 -2003
    +1002 1001
    +1002 -2004
    +-2004 1001
    +1003 -2002
    +-2003 1003
    +1004 -2002
    +-2001 -2003
    +1001 1003
    +1003 -2001
    +1002 -2001
    +-2002 -2003
    +5
    +1001 -2001
    +-2003 1001
    +1005 -2001
    +-2002 -2004
    +1111 -2003
    +
    +Sample Output:
    +4
    +1002 2004
    +1003 2002
    +1003 2003
    +1004 2002
    +4
    +2001 1002
    +2001 1003
    +2002 1003
    +2002 1004
    +0
    +1
    +2003 2001
    +0
    +
    +
    \ No newline at end of file diff --git a/html/a1140.html b/html/a1140.html new file mode 100644 index 0000000..e46fae6 --- /dev/null +++ b/html/a1140.html @@ -0,0 +1,27 @@ + + +

    1140. Look-and-say Sequence (20)

    +
    +

    Look-and-say sequence is a sequence of integers as the following: +

    +D, D1, D111, D113, D11231, D112213111, ...
    +

    +where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number. For example, the 2nd number means that there is one D in the 1st number, and hence it is D1; the 2nd number consists of one D (corresponding to D1) and one 1 (corresponding to 11), therefore the 3rd number is D111; or since the 4th number is D113, it consists of one D, two 1's, and one 3, so the next number must be D11231. This definition works for D = 1 as well. Now you are supposed to calculate the Nth number in a look-and-say sequence of a given digit D. +

    +

    +Input Specification: +

    +

    Each input file contains one test case, which gives D (in [0, 9]) and a positive integer N (<=40), separated by a space. +

    +

    +Output Specification: +

    +

    Print in a line the Nth number in a look-and-say sequence of D. +

    +Sample Input:
    +1 8
    +
    +Sample Output:
    +1123123111
    +
    +
    \ No newline at end of file diff --git a/html/a1141.html b/html/a1141.html new file mode 100644 index 0000000..313f652 --- /dev/null +++ b/html/a1141.html @@ -0,0 +1,51 @@ + + +

    1141. PAT Ranking of Institutions (25)

    +
    +

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<=105), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:

    +

    +ID Score School +

    +

    +where "ID" is a string of 6 characters with the first one representing the test level: "B" stands for the basic level, "A" the advanced level and "T" the top level; "Score" is an integer in [0, 100]; and "School" is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that "ID" is unique for each testee. +

    +

    +Output Specification: +

    +

    For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:

    +

    +Rank School TWS Ns +

    +

    +where "Rank" is the rank (start from 1) of the institution; "School" is the institution code (all in lower case); "TWS" is the total weighted score which is defined to be the integer part of "ScoreB/1.5 + ScoreA + ScoreT*1.5", where "ScoreX" is the total score of the testees belong to this institution on level X; and "Ns" is the total number of testees who belong to this institution. +

    +

    +The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes. +

    +Sample Input:
    +10
    +A57908 85 Au
    +B57908 54 LanX
    +A37487 60 au
    +T28374 67 CMU
    +T32486 24 hypu
    +A66734 92 cmu
    +B76378 71 AU
    +A47780 45 lanx
    +A72809 100 pku
    +A03274 45 hypu
    +
    +Sample Output:
    +5
    +1 cmu 192 2
    +1 au 192 3
    +3 pku 100 1
    +4 hypu 81 2
    +4 lanx 81 2
    +
    +
    \ No newline at end of file diff --git a/html/a1142.html b/html/a1142.html new file mode 100644 index 0000000..6a226f3 --- /dev/null +++ b/html/a1142.html @@ -0,0 +1,48 @@ + + +

    1142. Maximal Clique (25)

    +
    +

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adjacent vertex. (Quoted from https://en.wikipedia.org/wiki/Clique_(graph_theory)) +

    +

    +Now it is your job to judge if a given subset of vertices can form a maximal clique. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives two positive integers Nv (<= 200), the number of vertices in the graph, and Ne, the number of undirected edges. Then Ne lines follow, each gives a pair of vertices of an edge. The vertices are numbered from 1 to Nv.

    +

    After the graph, there is another positive integer M (<= 100). Then M lines of query follow, each first gives a positive number K (<= Nv), then followed by a sequence of K distinct vertices. All the numbers in a line are separated by a space. +

    +

    +Output Specification: +

    +

    For each of the M queries, print in a line "Yes" if the given subset of vertices can form a maximal clique; or if it is a clique but not a maximal clique, print "Not Maximal"; or if it is not a clique at all, print "Not a Clique".

    +Sample Input:
    +8 10
    +5 6
    +7 8
    +6 4
    +3 6
    +4 5
    +2 3
    +8 2
    +2 7
    +5 3
    +3 4
    +6
    +4 5 4 3 6
    +3 2 8 7
    +2 2 3
    +1 1
    +3 4 3 6
    +3 3 2 1
    +
    +Sample Output:
    +Yes
    +Yes
    +Yes
    +Yes
    +Not Maximal
    +Not a Clique
    +
    +
    \ No newline at end of file diff --git a/html/a1143.html b/html/a1143.html new file mode 100644 index 0000000..80c69ad --- /dev/null +++ b/html/a1143.html @@ -0,0 +1,43 @@ + + +

    1143. Lowest Common Ancestor (30)

    +
    +

    The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants. +

    +

    A binary search tree (BST) is recursively defined as a binary tree which has the following properties:

    + +

    +Given any two nodes in a BST, you are supposed to find their LCA. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives two positive integers: M (<= 1000), the number of pairs of nodes to be tested; and N (<= 10000), the number of keys in the BST, respectively. In the second line, N distinct integers are given as the preorder traversal sequence of the BST. Then M lines follow, each contains a pair of integer keys U and V. All the keys are in the range of int. +

    +

    +Output Specification: +

    +

    For each given pair of U and V, print in a line "LCA of U and V is A." if the LCA is found and A is the key. But if A is one of U and V, print "X is an ancestor of Y." where X is A and Y is the other node. If U or V is not found in the BST, print in a line "ERROR: U is not found." or "ERROR: V is not found." or "ERROR: U and V are not found.".

    +Sample Input:
    +6 8
    +6 3 1 2 5 4 8 7
    +2 5
    +8 7
    +1 9
    +12 -3
    +0 8
    +99 99
    +
    +Sample Output:
    +LCA of 2 and 5 is 3.
    +8 is an ancestor of 7.
    +ERROR: 9 is not found.
    +ERROR: 12 and -3 are not found.
    +ERROR: 0 is not found.
    +ERROR: 99 and 99 are not found.
    +
    +
    \ No newline at end of file diff --git a/html/a1144.html b/html/a1144.html new file mode 100644 index 0000000..32fe78d --- /dev/null +++ b/html/a1144.html @@ -0,0 +1,23 @@ + + +

    1144. The Missing Number (20)

    +
    +

    Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<= 105). Then N integers are given in the next line, separated by spaces. All the numbers are in the range of int. +

    +

    +Output Specification: +

    +

    Print in a line the smallest positive integer that is missing from the input list.

    +Sample Input:
    +10
    +5 -25 9 6 1 3 4 2 5 17
    +
    +Sample Output:
    +7
    +
    +
    \ No newline at end of file diff --git a/html/a1145.html b/html/a1145.html new file mode 100644 index 0000000..2a3bd69 --- /dev/null +++ b/html/a1145.html @@ -0,0 +1,25 @@ + + +

    1145. Hashing - Average Search Time (25)

    +
    +

    The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys from the table and output the average search time (the number of comparisons made to find whether or not the key is in the table). The hash function is defined to be "H(key) = key % TSize" where TSize is the maximum size of the hash table. Quadratic probing (with positive increments only) is used to solve the collisions.

    +

    Note that the table size is better to be prime. If the maximum size given by the user is not prime, you must re-define the table size to be the smallest prime number which is larger than the size given by the user.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains two positive numbers: MSize, N, and M, which are the user-defined table size, the number of input numbers, and the number of keys to be found, respectively. All the three numbers are no more than 104. Then N distinct positive integers are given in the next line. All the numbers in a line are separated by a space and are no more than 105.

    +

    +Output Specification: +

    +

    For each test case, in case it is impossible to insert some number, print in a line "X cannot be inserted." where X is the input number. Finally print in a line the average search time for all the M keys, accurate up to 1 decimal place. +

    +Sample Input:
    +4 5 4
    +10 6 4 15 11
    +11 4 15 2
    +
    +Sample Output:
    +15 cannot be inserted.
    +2.8
    +
    +
    \ No newline at end of file diff --git a/html/a1146.html b/html/a1146.html new file mode 100644 index 0000000..00c9c45 --- /dev/null +++ b/html/a1146.html @@ -0,0 +1,37 @@ + + +

    1146. Topological Order (25)

    +
    +

    This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test each of the options. +

    +
    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives two positive integers N (<= 1,000), the number of vertices in the graph, and M (<= 10,000), the number of directed edges. Then M lines follow, each gives the start and the end vertices of an edge. The vertices are numbered from 1 to N. After the graph, there is another positive integer K (<= 100). Then K lines of query follow, each gives a permutation of all the vertices. All the numbers in a line are separated by a space. +

    +

    +Output Specification: +

    +

    Print in a line all the indices of queries which correspond to "NOT a topological order". The indices start from zero. All the numbers are separated by a space, and there must no extra space at the beginning or the end of the line. It is graranteed that there is at least one answer.

    +Sample Input:
    +6 8
    +1 2
    +1 3
    +5 2
    +5 4
    +2 3
    +2 6
    +3 4
    +6 4
    +5
    +1 5 2 3 6 4
    +5 1 2 6 3 4
    +5 1 2 3 6 4
    +5 2 1 6 3 4
    +1 2 3 4 5 6
    +
    +Sample Output:
    +3 4
    +
    +
    \ No newline at end of file diff --git a/html/a1147.html b/html/a1147.html new file mode 100644 index 0000000..dfe465b --- /dev/null +++ b/html/a1147.html @@ -0,0 +1,33 @@ + + +

    1147. Heaps (30)

    +
    +

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to (in a min heap) the key of C. A common implementation of a heap is the binary heap, in which the tree is a complete binary tree. (Quoted from Wikipedia at https://en.wikipedia.org/wiki/Heap_(data_structure)) +

    +

    +Your job is to tell if a given complete binary tree is a heap. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives two positive integers: M (<= 100), the number of trees to be tested; and N (1 < N <= 1000), the number of keys in each tree, respectively. Then M lines follow, each contains N distinct integer keys (all in the range of int), which gives the level order traversal sequence of a complete binary tree. +

    +

    +Output Specification: +

    +

    For each given tree, print in a line "Max Heap" if it is a max heap, or "Min Heap" for a min heap, or "Not Heap" if it is not a heap at all. Then in the next line print the tree's postorder traversal sequence. All the numbers are separated by a space, and there must no extra space at the beginning or the end of the line.

    +Sample Input:
    +3 8
    +98 72 86 60 65 12 23 50
    +8 38 25 58 52 82 70 60
    +10 28 15 12 34 9 8 56
    +
    +Sample Output:
    +Max Heap
    +50 60 65 72 12 23 86 98
    +Min Heap
    +60 58 52 38 82 70 25 8
    +Not Heap
    +56 12 34 28 9 8 15 10
    +
    +
    \ No newline at end of file diff --git a/html/b1001.html b/html/b1001.html new file mode 100644 index 0000000..8be2451 --- /dev/null +++ b/html/b1001.html @@ -0,0 +1,18 @@ + + +

    1001. 害死人不偿命的(3n+1)猜想 (15)

    +
    +

    卡拉兹(Callatz)猜想:

    +

    对任何一个自然数n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把(3n+1)砍掉一半。这样一直反复砍下去,最后一定在某一步得到n=1。卡拉兹在1950年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业,一心只证(3n+1),以至于有人说这是一个阴谋,卡拉兹是在蓄意延缓美国数学界教学与科研的进展…… +

    +

    我们今天的题目不是证明卡拉兹猜想,而是对给定的任一不超过1000的正整数n,简单地数一下,需要多少步(砍几下)才能得到n=1? + +

    输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。

    +

    输出格式:输出从n计算到1需要的步数。

    +输入样例:
    +3
    +
    +输出样例:
    +5
    +
    +

    \ No newline at end of file diff --git a/html/b1002.html b/html/b1002.html new file mode 100644 index 0000000..be6c0e2 --- /dev/null +++ b/html/b1002.html @@ -0,0 +1,19 @@ + + +

    1002. 写出这个数 (20)

    +
    +

    读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。 + +

    +

    输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。

    +

    输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 + +空格,但一行中最后一个拼音数字后没有空格。 +

    +输入样例:
    +1234567890987654321123456789
    +
    +输出样例:
    +yi san wu
    +
    +
    \ No newline at end of file diff --git a/html/b1003.html b/html/b1003.html new file mode 100644 index 0000000..bed0b0d --- /dev/null +++ b/html/b1003.html @@ -0,0 +1,12 @@ + + +

    1003. 我要通过!(20)

    +
    +

    “答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。

    +

    得到“答案正确”的条件是:

    +

    +1. 字符串中必须仅有P, A, T这三种字符,不可以包含其它字符;
    +2. 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串;
    +3. 如果 aPbTc 是正确的,那么 aPbATca 也是正确的,其中 a, b, c 均或者是空字符串,或者是仅由字母 A 组成的字符串。

    + +现在就请你为PAT写一个自动裁判程序,判定哪些字符串是可以获得“答案正确”的。
    \ No newline at end of file diff --git a/html/b1004.html b/html/b1004.html new file mode 100644 index 0000000..d608ddb --- /dev/null +++ b/html/b1004.html @@ -0,0 +1,25 @@ + + +

    1004. 成绩排名 (20)

    +
    +

    读入n名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。

    +

    输入格式:每个测试输入包含1个测试用例,格式为

    +  第1行:正整数n
    +  第2行:第1个学生的姓名 学号 成绩
    +  第3行:第2个学生的姓名 学号 成绩
    +  ... ... ...
    +  第n+1行:第n个学生的姓名 学号 成绩
    +
    +其中姓名和学号均为不超过10个字符的字符串,成绩为0到100之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。

    +

    输出格式:对每个测试用例输出2行,第1行是成绩最高学生的姓名和学号,第2行是成绩最低学生的姓名和学号,字符串间有1空格。

    +输入样例:
    +3
    +Joe Math990112 89
    +Mike CS991301 100
    +Mary EE990830 95
    +
    +输出样例:
    +Mike CS991301
    +Joe Math990112
    +
    +
    \ No newline at end of file diff --git a/html/b1005.html b/html/b1005.html new file mode 100644 index 0000000..e238f57 --- /dev/null +++ b/html/b1005.html @@ -0,0 +1,17 @@ + + +

    1005. 继续(3n+1)猜想 (25)

    +
    +

    卡拉兹(Callatz)猜想已经在1001中给出了描述。在这个题目里,情况稍微有些复杂。

    +

    当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数。例如对n=3进行验证的时候,我们需要计算3、5、8、4、2、1,则当我们对n=5、8、4、2进行验证的时候,就可以直接判定卡拉兹猜想的真伪,而不需要重复计算,因为这4个数已经在验证3的时候遇到过了,我们称5、8、4、2是被3“覆盖”的数。我们称一个数列中的某个数n为“关键数”,如果n不能被数列中的其他数字所覆盖。

    +

    现在给定一系列待验证的数字,我们只需要验证其中的几个关键数,就可以不必再重复验证余下的数字。你的任务就是找出这些关键数字,并按从大到小的顺序输出它们。

    +

    输入格式:每个测试输入包含1个测试用例,第1行给出一个正整数K(&lt100;),第2行给出K个互不相同的待验证的正整数n(1&ltn;<=100)的值,数字间用空格隔开。

    +

    输出格式:每个测试用例的输出占一行,按从大到小的顺序输出关键数字。数字间用1个空格隔开,但一行中最后一个数字后没有空格。

    +输入样例:
    +6
    +3 5 6 7 8 11
    +
    +输出样例:
    +7 6
    +
    +
    \ No newline at end of file diff --git a/html/b1006.html b/html/b1006.html new file mode 100644 index 0000000..9dfe8a7 --- /dev/null +++ b/html/b1006.html @@ -0,0 +1,20 @@ + + +

    1006. 换个格式输出整数 (15)

    +
    +

    让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(&lt10;),换个格式来输出任一个不超过3位的正整数。例如234应该被输出为BBSSS1234,因为它有2个“百”、3个“十”、以及个位的4。

    +

    输入格式:每个测试输入包含1个测试用例,给出正整数n(&lt1000;)。

    +

    输出格式:每个测试用例的输出占一行,用规定的格式输出n。

    +输入样例1:
    +234
    +
    +输出样例1:
    +BBSSS1234
    +
    +输入样例2:
    +23
    +
    +输出样例2:
    +SS123
    +
    +
    \ No newline at end of file diff --git a/html/b1007.html b/html/b1007.html new file mode 100644 index 0000000..05eead8 --- /dev/null +++ b/html/b1007.html @@ -0,0 +1,16 @@ + + +

    1007. 素数对猜想 (20)

    +
    +

    让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数。显然有 d1=1 且对于n&gt1;有 dn 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。 +

    +

    现给定任意正整数N (< 105),请计算不超过N的满足猜想的素数对的个数。

    +

    输入格式:每个测试输入包含1个测试用例,给出正整数N。

    +

    输出格式:每个测试用例的输出占一行,不超过N的满足猜想的素数对的个数。

    +输入样例:
    +20
    +
    +输出样例:
    +4
    +
    +
    \ No newline at end of file diff --git a/html/b1008.html b/html/b1008.html new file mode 100644 index 0000000..9807e8b --- /dev/null +++ b/html/b1008.html @@ -0,0 +1,15 @@ + + +

    1008. 数组元素循环右移问题 (20)

    +
    +

    一个数组A中存有N(N&gt0;)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1……AN-1)变换为(AN-M …… AN-1 A0 A1……AN-M-1)(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?

    +

    输入格式:每个输入包含一个测试用例,第1行输入N ( 1<=N<=100)、M(M>=0);第2行输入N个整数,之间用空格分隔。

    +

    输出格式:在一行中输出循环右移M位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。

    +输入样例:
    +6 2
    +1 2 3 4 5 6
    +
    +输出样例:
    +5 6 1 2 3 4
    +
    +
    \ No newline at end of file diff --git a/html/b1009.html b/html/b1009.html new file mode 100644 index 0000000..984eaf9 --- /dev/null +++ b/html/b1009.html @@ -0,0 +1,14 @@ + + +

    1009. 说反话 (20)

    +
    +

    给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。

    +

    输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。

    +

    输出格式:每个测试用例的输出占一行,输出倒序后的句子。

    +输入样例:
    +Hello World Here I Come
    +
    +输出样例:
    +Come I Here World Hello
    +
    +
    \ No newline at end of file diff --git a/html/b1010.html b/html/b1010.html new file mode 100644 index 0000000..3128d1d --- /dev/null +++ b/html/b1010.html @@ -0,0 +1,14 @@ + + +

    1010. 一元多项式求导 (25)

    +
    +

    设计函数求一元多项式的导数。(注:xn(n为整数)的一阶导数为n*xn-1。)

    +

    输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。

    +

    输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是0,但是表示为“0 0”。

    +输入样例:
    +3 4 -5 2 6 1 -2 0
    +
    +输出样例:
    +12 3 -10 1 6 0
    +
    +
    \ No newline at end of file diff --git a/html/b1011.html b/html/b1011.html new file mode 100644 index 0000000..6d4746f --- /dev/null +++ b/html/b1011.html @@ -0,0 +1,28 @@ + + +

    1011. A+B和C (15)

    +
    +

    给定区间[-231, 231]内的3个整数A、B和C,请判断A+B是否大于C。 +

    +

    +输入格式: +

    +

    输入第1行给出正整数T(<=10),是测试用例的个数。随后给出T组测试用例,每组占一行,顺序给出A、B和C。整数间以空格分隔。

    +

    +输出格式: +

    +

    对每组测试用例,在一行中输出“Case #X: true”如果A+B>C,否则输出“Case #X: false”,其中X是测试用例的编号(从1开始)。

    +输入样例:
    +4
    +1 2 3
    +2 3 4
    +2147483647 0 2147483646
    +0 -2147483648 -2147483647
    +
    +输出样例:
    +Case #1: false
    +Case #2: true
    +Case #3: true
    +Case #4: false
    +
    +
    \ No newline at end of file diff --git a/html/b1012.html b/html/b1012.html new file mode 100644 index 0000000..f1c03f5 --- /dev/null +++ b/html/b1012.html @@ -0,0 +1,33 @@ + + +

    1012. 数字分类 (20)

    +
    +

    给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字:

    +
  • A1 = 能被5整除的数字中所有偶数的和; +
  • A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...; +
  • A3 = 被5除后余2的数字的个数; +
  • A4 = 被5除后余3的数字的平均数,精确到小数点后1位; +
  • A5 = 被5除后余4的数字中最大数字。 + +

    +输入格式: +

    +

    每个输入包含1个测试用例。每个测试用例先给出一个不超过1000的正整数N,随后给出N个不超过1000的待分类的正整数。数字间以空格分隔。

    +

    +输出格式: +

    +

    对给定的N个正整数,按题目要求计算A1~A5并在一行中顺序输出。数字间以空格分隔,但行末不得有多余空格。

    +

    若其中某一类数字不存在,则在相应位置输出“N”。

    +输入样例1:
    +13 1 2 3 4 5 6 7 8 9 10 20 16 18
    +
    +输出样例1:
    +30 11 2 9.7 9
    +
    +输入样例2:
    +8 1 2 4 5 6 7 9 16
    +
    +输出样例2:
    +N 11 2 N 9
    +
    +
  • \ No newline at end of file diff --git a/html/b1013.html b/html/b1013.html new file mode 100644 index 0000000..c282d34 --- /dev/null +++ b/html/b1013.html @@ -0,0 +1,23 @@ + + +

    1013. 数素数 (20)

    +
    +

    +令Pi表示第i个素数。现任给两个正整数M <= N <= 104,请输出PM到PN的所有素数。

    +

    +输入格式: +

    +

    输入在一行中给出M和N,其间以空格分隔。

    +

    +输出格式: +

    +

    输出从PM到PN的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。

    +输入样例:
    +5 27
    +
    +输出样例:
    +11 13 17 19 23 29 31 37 41 43
    +47 53 59 61 67 71 73 79 83 89
    +97 101 103
    +
    +
    \ No newline at end of file diff --git a/html/b1014.html b/html/b1014.html new file mode 100644 index 0000000..bec1870 --- /dev/null +++ b/html/b1014.html @@ -0,0 +1,28 @@ + + +

    1014. 福尔摩斯的约会 (20)

    +
    +

    大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! +3485djDkxh4hhGE +2984akDfkkkkggEdsb +s&hgsfdk; +d&Hyscvnm;”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母'D',代表星期四;第2对相同的字符是'E',那是第5个英文字母,代表一天里的第14个钟头(于是一天的0点到23点由数字0到9、以及大写字母A到N表示);后面两字符串第1对相同的英文字母's'出现在第4个位置(从0开始计数)上,代表第4分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。

    +

    +输入格式: +

    +

    输入在4行中分别给出4个非空、不包含空格、且长度不超过60的字符串。 +

    +

    +输出格式: +

    +

    在一行中输出约会的时间,格式为“DAY HH:MM”,其中“DAY”是某星期的3字符缩写,即MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期四,FRI表示星期五,SAT表示星期六,SUN表示星期日。题目输入保证每个测试存在唯一解。

    +输入样例:
    +3485djDkxh4hhGE 
    +2984akDfkkkkggEdsb 
    +s&hgsfdk; 
    +d&Hyscvnm;
    +
    +输出样例:
    +THU 14:04
    +
    +
    \ No newline at end of file diff --git a/html/b1015.html b/html/b1015.html new file mode 100644 index 0000000..ce552a2 --- /dev/null +++ b/html/b1015.html @@ -0,0 +1,17 @@ + + +

    1015. 德才论 (25)

    +
    +

    +宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。” +

    +

    +现给出一批考生的德才分数,请根据司马光的理论给出录取排名。 +

    +

    +输入格式: +

    +

    输入第1行给出3个正整数,分别为:N(<=105),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线L的考生也按总分排序,但排在第三类考生之后。 +

    +

    随后N行,每行给出一位考生的信息,包括:准考证号、德分、才分,其中准考证号为8位整数,德才分为区间[0, 100]内的整数。数字间以空格分隔。

    +
    \ No newline at end of file diff --git a/html/b1016.html b/html/b1016.html new file mode 100644 index 0000000..36d5c41 --- /dev/null +++ b/html/b1016.html @@ -0,0 +1,28 @@ + + +

    1016. 部分A+B (15)

    +
    +

    正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA。例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6。

    +

    现给定A、DA、B、DB,请编写程序计算PA + PB。

    +

    +输入格式: +

    +

    输入在一行中依次给出A、DA、B、DB,中间以空格分隔,其中0 < A, B < 1010。

    +

    +输出格式: +

    +

    在一行中输出PA + PB的值。 +

    +输入样例1:
    +3862767 6 13530293 3
    +
    +输出样例1:
    +399
    +
    +输入样例2:
    +3862767 1 13530293 8
    +
    +输出样例2:
    +0
    +
    +
    \ No newline at end of file diff --git a/html/b1017.html b/html/b1017.html new file mode 100644 index 0000000..3d20f9b --- /dev/null +++ b/html/b1017.html @@ -0,0 +1,23 @@ + + +

    1017. A除以B (20)

    +
    +

    +本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数。你需要输出商数Q和余数R,使得A = B * Q + R成立。

    +

    +输入格式: +

    +

    输入在1行中依次给出A和B,中间以1空格分隔。 +

    +

    +输出格式: +

    +

    在1行中依次输出Q和R,中间以1空格分隔。 +

    +输入样例:
    +123456789050987654321 7
    +
    +输出样例:
    +17636684150141093474 3
    +
    +
    \ No newline at end of file diff --git a/html/b1018.html b/html/b1018.html new file mode 100644 index 0000000..5a12bc4 --- /dev/null +++ b/html/b1018.html @@ -0,0 +1,39 @@ + + +

    1018. 锤子剪刀布 (20)

    +
    +

    +大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:

    +
    +

    +现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。 +

    +

    +输入格式: +

    +

    输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。 +

    +

    +输出格式: +

    +

    输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯一,则输出按字母序最小的解。 +

    +输入样例:
    +10
    +C J
    +J B
    +C B
    +B B
    +B C
    +C C
    +C B
    +J B
    +B C
    +J J
    +
    +输出样例:
    +5 3 2
    +2 3 5
    +B B
    +
    +
    \ No newline at end of file diff --git a/html/b1019.html b/html/b1019.html new file mode 100644 index 0000000..6f542fe --- /dev/null +++ b/html/b1019.html @@ -0,0 +1,41 @@ + + +

    1019. 数字黑洞 (20)

    +
    +

    +给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字。一直重复这样做,我们很快会停在有“数字黑洞”之称的6174,这个神奇的数字也叫Kaprekar常数。

    +

    例如,我们从6767开始,将得到

    +

    +7766 - 6677 = 1089
    +9810 - 0189 = 9621
    +9621 - 1269 = 8352
    +8532 - 2358 = 6174
    +7641 - 1467 = 6174
    +... ...

    +

    现给定任意4位正整数,请编写程序演示到达黑洞的过程。

    +

    +输入格式: +

    +

    输入给出一个(0, 10000)区间内的正整数N。 +

    +

    +输出格式: +

    +

    如果N的4位数字全相等,则在一行内输出“N - N = 0000”;否则将计算的每一步在一行内输出,直到6174作为差出现,输出格式见样例。注意每个数字按4位数格式输出。 +

    +输入样例1:
    +6767
    +
    +输出样例1:
    +7766 - 6677 = 1089
    +9810 - 0189 = 9621
    +9621 - 1269 = 8352
    +8532 - 2358 = 6174
    +
    +输入样例2:
    +2222
    +
    +输出样例2:
    +2222 - 2222 = 0000
    +
    +
    \ No newline at end of file diff --git a/html/b1020.html b/html/b1020.html new file mode 100644 index 0000000..e71619b --- /dev/null +++ b/html/b1020.html @@ -0,0 +1,24 @@ + + +

    1020. 月饼 (25)

    +
    +

    月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。 +

    +

    注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有3种月饼,其库存量分别为18、15、10万吨,总售价分别为75、72、45亿元。如果市场的最大需求量只有20万吨,那么我们最大收益策略应该是卖出全部15万吨第2种月饼、以及5万吨第3种月饼,获得 72 + 45/2 = 94.5(亿元)。

    +

    +输入格式: +

    +

    每个输入包含1个测试用例。每个测试用例先给出一个不超过1000的正整数N表示月饼的种类数、以及不超过500(以万吨为单位)的正整数D表示市场最大需求量。随后一行给出N个正数表示每种月饼的库存量(以万吨为单位);最后一行给出N个正数表示每种月饼的总售价(以亿元为单位)。数字间以空格分隔。

    +

    +输出格式: +

    +

    对每组测试用例,在一行中输出最大收益,以亿元为单位并精确到小数点后2位。

    +输入样例:
    +3 20
    +18 15 10
    +75 72 45
    +
    +输出样例:
    +94.50
    +
    +
    \ No newline at end of file diff --git a/html/b1021.html b/html/b1021.html new file mode 100644 index 0000000..e9a0ebc --- /dev/null +++ b/html/b1021.html @@ -0,0 +1,22 @@ + + +

    1021. 个位数统计 (15)

    +
    +

    给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,...,k-1, dk-1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定N = 100311,则有2个0,3个1,和1个3。

    +

    +输入格式: +

    +

    每个输入包含1个测试用例,即一个不超过1000位的正整数N。

    +

    +输出格式: +

    +

    对N中每一种不同的个位数字,以D:M的格式在一行中输出该位数字D及其在N中出现的次数M。要求按D的升序输出。

    +输入样例:
    +100311
    +
    +输出样例:
    +0:2
    +1:3
    +3:1
    +
    +
    \ No newline at end of file diff --git a/html/b1022.html b/html/b1022.html new file mode 100644 index 0000000..854d787 --- /dev/null +++ b/html/b1022.html @@ -0,0 +1,24 @@ + + +

    1022. D进制的A+B (20)

    +
    +

    +输入两个非负10进制整数A和B(<=230-1),输出A+B的D (1 < D <= 10)进制数。 +

    +

    +输入格式: +

    +

    输入在一行中依次给出3个整数A、B和D。 +

    +

    +输出格式: +

    +

    输出A+B的D进制数。 +

    +输入样例:
    +123 456 8
    +
    +输出样例:
    +1103
    +
    +
    \ No newline at end of file diff --git a/html/b1023.html b/html/b1023.html new file mode 100644 index 0000000..f6be3ce --- /dev/null +++ b/html/b1023.html @@ -0,0 +1,25 @@ + + +

    1023. 组个最小数 (20)

    +
    +

    +给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意0不能做首位)。例如:给定两个0,两个1,三个5,一个8,我们得到的最小的数就是10015558。

    +

    现给定数字,请编写程序输出能够组成的最小的数。

    +

    +输入格式: +

    +

    每个输入包含1个测试用例。每个测试用例在一行中给出10个非负整数,顺序表示我们拥有数字0、数字1、……数字9的个数。整数间用一个空格分隔。10个数字的总个数不超过50,且至少拥有1个非0的数字。 +

    +

    +输出格式: +

    +

    +在一行中输出能够组成的最小的数。 +

    +输入样例:
    +2 2 0 0 0 3 0 0 1 0
    +
    +输出样例:
    +10015558
    +
    +
    \ No newline at end of file diff --git a/html/b1024.html b/html/b1024.html new file mode 100644 index 0000000..b2709d2 --- /dev/null +++ b/html/b1024.html @@ -0,0 +1,27 @@ + + +

    1024. 科学计数法 (20)

    +
    +

    科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+-][0-9]+,即数字的整数部分只有1位,小数部分至少有1位,该数字及其指数部分的正负号即使对正数也必定明确给出。

    +

    现以科学计数法的格式给出实数A,请编写程序按普通数字表示法输出A,并保证所有有效位都被保留。

    +

    +输入格式: +

    +

    每个输入包含1个测试用例,即一个以科学计数法表示的实数A。该数字的存储长度不超过9999字节,且其指数的绝对值不超过9999。

    +

    +输出格式: +

    +

    对每个测试用例,在一行中按普通数字表示法输出A,并保证所有有效位都被保留,包括末尾的0。

    +输入样例1:
    ++1.23400E-03
    +
    +输出样例1:
    +0.00123400
    +
    +输入样例2:
    +-1.2E+10
    +
    +输出样例2:
    +-12000000000
    +
    +
    \ No newline at end of file diff --git a/html/b1025.html b/html/b1025.html new file mode 100644 index 0000000..d588353 --- /dev/null +++ b/html/b1025.html @@ -0,0 +1,34 @@ + + +

    1025. 反转链表 (25)

    +
    +

    给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转。

    +

    +输入格式: +

    +

    每个输入包含1个测试用例。每个测试用例第1行给出第1个结点的地址、结点总个数正整数N(<= 105)、以及正整数K(<=N),即要求反转的子链结点的个数。结点的地址是5位非负整数,NULL地址用-1表示。

    +

    接下来有N行,每行格式为:

    +

    Address Data Next

    +

    其中Address是结点地址,Data是该结点保存的整数数据,Next是下一结点的地址。

    +

    +输出格式: +

    +

    对每个测试用例,顺序输出反转后的链表,其上每个结点占一行,格式与输入相同。

    +输入样例:
    +00100 6 4
    +00000 4 99999
    +00100 1 12309
    +68237 6 -1
    +33218 3 00000
    +99999 5 68237
    +12309 2 33218
    +
    +输出样例:
    +00000 4 33218
    +33218 3 12309
    +12309 2 00100
    +00100 1 99999
    +99999 5 68237
    +68237 6 -1
    +
    +
    \ No newline at end of file diff --git a/html/b1026.html b/html/b1026.html new file mode 100644 index 0000000..a9ec272 --- /dev/null +++ b/html/b1026.html @@ -0,0 +1,27 @@ + + +

    1026. 程序运行时间(15)

    +
    +

    +要获得一个C语言程序的运行时间,常用的方法是调用头文件time.h,其中提供了clock()函数,可以捕捉从程序开始运行到clock()被调用时所耗费的时间。这个时间单位是clock tick,即“时钟打点”。同时还有一个常数CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数f的运行时间,我们只要在调用f之前先调用clock(),获得一个时钟打点数C1;在f执行完成后再调用clock(),获得另一个时钟打点数C2;两次获得的时钟打点数之差(C2-C1)就是f运行所消耗的时钟打点数,再除以常数CLK_TCK,就得到了以秒为单位的运行时间。 +

    +

    这里不妨简单假设常数CLK_TCK为100。现给定被测函数前后两次获得的时钟打点数,请你给出被测函数运行的时间。

    +

    +输入格式: +

    +

    +输入在一行中顺序给出2个整数C1和C2。注意两次获得的时钟打点数肯定不相同,即C1 < C2,并且取值在[0, 107]。 +

    +

    +输出格式: +

    +

    +在一行中输出被测函数运行的时间。运行时间必须按照“hh:mm:ss”(即2位的“时:分:秒”)格式输出;不足1秒的时间四舍五入到秒。 +

    +输入样例:
    +123 4577973
    +
    +输出样例:
    +12:42:59
    +
    +
    \ No newline at end of file diff --git a/html/b1027.html b/html/b1027.html new file mode 100644 index 0000000..b7daf5e --- /dev/null +++ b/html/b1027.html @@ -0,0 +1,38 @@ + + +

    1027. 打印沙漏(20)

    +
    +

    +本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印

    +*****
    + ***
    +  *
    + ***
    +*****
    +
    +

    所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。

    +

    给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。

    +

    +输入格式: +

    +

    +输入在一行给出1个正整数N(<=1000)和一个符号,中间以空格分隔。 +

    +

    +输出格式: +

    +

    +首先打印出由给定符号组成的最大的沙漏形状,最后在一行中输出剩下没用掉的符号数。 +

    +输入样例:
    +19 *
    +
    +输出样例:
    +*****
    + ***
    +  *
    + ***
    +*****
    +2
    +
    +
    \ No newline at end of file diff --git a/html/b1028.html b/html/b1028.html new file mode 100644 index 0000000..70a2890 --- /dev/null +++ b/html/b1028.html @@ -0,0 +1,33 @@ + + +

    1028. 人口普查(20)

    +
    +

    +某城镇进行人口普查,得到了全体居民的生日。现请你写个程序,找出镇上最年长和最年轻的人。 +

    +

    这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过200岁的老人,而今天是2014年9月6日,所以超过200岁的生日和未出生的生日都是不合理的,应该被过滤掉。 +

    +

    +输入格式: +

    +

    +输入在第一行给出正整数N,取值在(0, 105];随后N行,每行给出1个人的姓名(由不超过5个英文字母组成的字符串)、以及按“yyyy/mm/dd”(即年/月/日)格式给出的生日。题目保证最年长和最年轻的人没有并列。 +

    +

    +输出格式: +

    +

    +在一行中顺序输出有效生日的个数、最年长人和最年轻人的姓名,其间以空格分隔。 +

    +输入样例:
    +5
    +John 2001/05/12
    +Tom 1814/09/06
    +Ann 2121/01/30
    +James 1814/09/05
    +Steve 1967/11/20
    +
    +输出样例:
    +3 Tom John
    +
    +
    \ No newline at end of file diff --git a/html/b1029.html b/html/b1029.html new file mode 100644 index 0000000..7f4cd14 --- /dev/null +++ b/html/b1029.html @@ -0,0 +1,25 @@ + + +

    1029. 旧键盘(20)

    +
    +

    +旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。 +

    +

    +输入格式: +

    +

    输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符的串,由字母A-Z(包括大、小写)、数字0-9、以及下划线“_”(代表空格)组成。题目保证2个字符串均非空。 +

    +

    +输出格式: +

    +

    +按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有1个坏键。

    +输入样例:
    +7_This_is_a_test
    +_hs_s_a_es
    +
    +输出样例:
    +7TI
    +
    +
    \ No newline at end of file diff --git a/html/b1030.html b/html/b1030.html new file mode 100644 index 0000000..c501ff5 --- /dev/null +++ b/html/b1030.html @@ -0,0 +1,28 @@ + + +

    1030. 完美数列(25)

    +
    +

    +给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果M <= m * p,则称这个数列是完美数列。 +

    +

    现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。

    +

    +输入格式: +

    +

    +输入第一行给出两个正整数N和p,其中N(<= 105)是输入的正整数的个数,p(<= 109)是给定的参数。第二行给出N个正整数,每个数不超过109。 +

    +

    +输出格式: +

    +

    +在一行中输出最多可以选择多少个数可以用它们组成一个完美数列。 +

    +输入样例:
    +10 8
    +2 3 20 4 5 1 6 7 8 9
    +
    +输出样例:
    +8
    +
    +
    \ No newline at end of file diff --git a/html/b1031.html b/html/b1031.html new file mode 100644 index 0000000..81fc7b9 --- /dev/null +++ b/html/b1031.html @@ -0,0 +1,46 @@ + + +

    1031. 查验身份证(15)

    +
    +

    +一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下: +

    +

    首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值:

    +

    +Z:0 1 2 3 4 5 6 7 8 9 10
    +M:1 0 X 9 8 7 6 5 4 3 2 +

    +

    现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码。

    +

    +输入格式: +

    +

    +输入第一行给出正整数N(<= 100)是输入的身份证号码的个数。随后N行,每行给出1个18位身份证号码。 +

    +

    +输出格式: +

    +

    +按照输入的顺序每行输出1个有问题的身份证号码。这里并不检验前17位是否合理,只检查前17位是否全为数字且最后1位校验码计算准确。如果所有号码都正常,则输出“All passed”。 +

    +输入样例1:
    +4
    +320124198808240056
    +12010X198901011234
    +110108196711301866
    +37070419881216001X
    +
    +输出样例1:
    +12010X198901011234
    +110108196711301866
    +37070419881216001X
    +
    +输入样例2:
    +2
    +320124198808240056
    +110108196711301862
    +
    +输出样例2:
    +All passed
    +
    +
    \ No newline at end of file diff --git a/html/b1032.html b/html/b1032.html new file mode 100644 index 0000000..b697c8d --- /dev/null +++ b/html/b1032.html @@ -0,0 +1,31 @@ + + +

    1032. 挖掘机技术哪家强(20)

    +
    +

    +为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。

    +

    +输入格式: +

    +

    +输入在第1行给出不超过105的正整数N,即参赛人数。随后N行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从1开始连续编号)、及其比赛成绩(百分制),中间以空格分隔。 +

    +

    +输出格式: +

    +

    +在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。 +

    +输入样例:
    +6
    +3 65
    +2 80
    +1 100
    +2 70
    +3 40
    +3 0
    +
    +输出样例:
    +2 150
    +
    +
    \ No newline at end of file diff --git a/html/b1033.html b/html/b1033.html new file mode 100644 index 0000000..14d2bec --- /dev/null +++ b/html/b1033.html @@ -0,0 +1,27 @@ + + +

    1033. 旧键盘打字(20)

    +
    +

    +旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样? +

    +

    +输入格式: +

    +

    输入在2行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过105个字符的串。可用的字符包括字母[a-z, A-Z]、数字0-9、以及下划线“_”(代表空格)、“,”、“.”、“-”、“+”(代表上档键)。题目保证第2行输入的文字串非空。 +

    +

    注意:如果上档键坏掉了,那么大写的英文字母无法被打出。 + +

    +输出格式: +

    +

    +在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。

    +输入样例:
    +7+IE.
    +7_This_is_a_test.
    +
    +输出样例:
    +_hs_s_a_tst
    +
    +

    \ No newline at end of file diff --git a/html/b1034.html b/html/b1034.html new file mode 100644 index 0000000..5e79cef --- /dev/null +++ b/html/b1034.html @@ -0,0 +1,37 @@ + + +

    1034. 有理数四则运算(20)

    +
    +

    +本题要求编写程序,计算2个有理数的和、差、积、商。

    +

    +输入格式: +

    +

    +输入在一行中按照“a1/b1 a2/b2”的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为0。 +

    +

    +输出格式: +

    +

    +分别在4行中按照“有理数1 运算符 有理数2 = 结果”的格式顺序输出2个有理数的和、差、积、商。注意输出的每个有理数必须是该有理数的最简形式“k a/b”,其中k是整数部分,a/b是最简分数部分;若为负数,则须加括号;若除法分母为0,则输出“Inf”。题目保证正确的输出中没有超过整型范围的整数。 +

    +输入样例1:
    +2/3 -4/2
    +
    +输出样例1:
    +2/3 + (-2) = (-1 1/3)
    +2/3 - (-2) = 2 2/3
    +2/3 * (-2) = (-1 1/3)
    +2/3 / (-2) = (-1/3)
    +
    +输入样例2:
    +5/3 0/6
    +
    +输出样例2:
    +1 2/3 + 0 = 1 2/3
    +1 2/3 - 0 = 1 2/3
    +1 2/3 * 0 = 0
    +1 2/3 / 0 = Inf
    +
    +
    \ No newline at end of file diff --git a/html/b1035.html b/html/b1035.html new file mode 100644 index 0000000..bf8d93e --- /dev/null +++ b/html/b1035.html @@ -0,0 +1,40 @@ + + +

    1035. 插入与归并(25)

    +
    +

    根据维基百科的定义:

    +

    插入排序是迭代算法,逐一获得输入数据,逐步产生有序的输出序列。每步迭代中,算法从输入序列中取出一元素,将之插入有序序列中正确的位置。如此迭代直到全部元素有序。

    +

    +归并排序进行如下迭代操作:首先将原始序列看成N个只包含1个元素的有序子序列,然后每次迭代归并两个相邻的有序子序列,直到最后只剩下1个有序的序列。

    +

    现给定原始序列和由某排序算法产生的中间序列,请你判断该算法究竟是哪种排序算法?

    +

    +输入格式: +

    +

    +输入在第一行给出正整数N (<=100);随后一行给出原始序列的N个整数;最后一行给出由某排序算法产生的中间序列。这里假设排序的目标序列是升序。数字间以空格分隔。 +

    +

    +输出格式: +

    +首先在第1行中输出“Insertion Sort”表示插入排序、或“Merge Sort”表示归并排序;然后在第2行中输出用该排序算法再迭代一轮的结果序列。题目保证每组测试的结果是唯一的。数字间以空格分隔,且行末不得有多余空格。 +

    +

    +输入样例1:
    +10
    +3 1 2 8 7 5 9 4 6 0
    +1 2 3 7 8 5 9 4 6 0
    +
    +输出样例1:
    +Insertion Sort
    +1 2 3 5 7 8 9 4 6 0
    +
    +输入样例2:
    +10
    +3 1 2 8 7 5 9 4 0 6
    +1 3 2 8 5 7 4 9 0 6
    +
    +输出样例2:
    +Merge Sort
    +1 2 3 8 4 5 7 9 0 6
    +
    +
    \ No newline at end of file diff --git a/html/b1036.html b/html/b1036.html new file mode 100644 index 0000000..06d2e5c --- /dev/null +++ b/html/b1036.html @@ -0,0 +1,29 @@ + + +

    1036. 跟奥巴马一起编程(15)

    +
    +

    +美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧! +

    +

    +输入格式: +

    +

    +输入在一行中给出正方形边长N(3<=N<=20)和组成正方形边的某种字符C,间隔一个空格。 +

    +

    +输出格式: +

    +

    +输出由给定字符C画出的正方形。但是注意到行间距比列间距大,所以为了让结果看上去更像正方形,我们输出的行数实际上是列数的50%(四舍五入取整)。

    +输入样例:
    +10 a
    +
    +输出样例:
    +aaaaaaaaaa
    +a        a
    +a        a
    +a        a
    +aaaaaaaaaa
    +
    +
    \ No newline at end of file diff --git a/html/b1037.html b/html/b1037.html new file mode 100644 index 0000000..bfd97d7 --- /dev/null +++ b/html/b1037.html @@ -0,0 +1,30 @@ + + +

    1037. 在霍格沃茨找零钱(20)

    +
    +

    +如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”现在,给定哈利应付的价钱P和他实付的钱A,你的任务是写一个程序来计算他应该被找的零钱。 +

    +

    +输入格式: +

    +

    输入在1行中分别给出P和A,格式为“Galleon.Sickle.Knut”,其间用1个空格分隔。这里Galleon是[0, 107]区间内的整数,Sickle是[0, 17)区间内的整数,Knut是[0, 29)区间内的整数。 +

    +

    +输出格式: +

    +

    +在一行中用与输入同样的格式输出哈利应该被找的零钱。如果他没带够钱,那么输出的应该是负数。

    +输入样例1:
    +10.16.27 14.1.28
    +
    +输出样例1:
    +3.2.1
    +
    +输入样例2:
    +14.1.28 10.16.27
    +
    +输出样例2:
    +-3.2.1
    +
    +
    \ No newline at end of file diff --git a/html/b1038.html b/html/b1038.html new file mode 100644 index 0000000..44a6d99 --- /dev/null +++ b/html/b1038.html @@ -0,0 +1,27 @@ + + +

    1038. 统计同成绩学生(20)

    +
    +

    +本题要求读入N名学生的成绩,将获得某一给定分数的学生人数输出。

    +

    +输入格式: +

    +

    +输入在第1行给出不超过105的正整数N,即学生总人数。随后1行给出N名学生的百分制整数成绩,中间以空格分隔。最后1行给出要查询的分数个数K(不超过N的正整数),随后是K个分数,中间以空格分隔。 +

    +

    +输出格式: +

    +

    +在一行中按查询顺序给出得分等于指定分数的学生人数,中间以空格分隔,但行末不得有多余空格。 +

    +输入样例:
    +10
    +60 75 90 55 75 99 82 90 75 50
    +3 75 90 88
    +
    +输出样例:
    +3 2 0
    +
    +
    \ No newline at end of file diff --git a/html/b1039.html b/html/b1039.html new file mode 100644 index 0000000..a6c0f4f --- /dev/null +++ b/html/b1039.html @@ -0,0 +1,34 @@ + + +

    1039. 到底买不买(20)

    +
    +

    +小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖。于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子;如果不是,那么告诉她缺了多少珠子。

    +

    为方便起见,我们用[0-9]、[a-z]、[A-Z]范围内的字符来表示颜色。例如在图1中,第3串是小红想做的珠串;那么第1串可以买,因为包含了全部她想要的珠子,还多了8颗不需要的珠子;第2串不能买,因为没有黑色珠子,并且少了一颗红色的珠子。

    +

    图 1
    +

    +输入格式: +

    +

    每个输入包含1个测试用例。每个测试用例分别在2行中先后给出摊主的珠串和小红想做的珠串,两串都不超过1000个珠子。 +

    +

    +输出格式: +

    +

    +如果可以买,则在一行中输出“Yes”以及有多少多余的珠子;如果不可以买,则在一行中输出“No”以及缺了多少珠子。其间以1个空格分隔。 +

    +输入样例1:
    +ppRYYGrrYBR2258
    +YrR8RrY
    +
    +输出样例1:
    +Yes 8
    +
    +输入样例2:
    +ppRYYGrrYB225
    +YrR8RrY
    +
    +输出样例2:
    +No 2
    +
    +
    \ No newline at end of file diff --git a/html/b1040.html b/html/b1040.html new file mode 100644 index 0000000..1d4aa4d --- /dev/null +++ b/html/b1040.html @@ -0,0 +1,25 @@ + + +

    1040. 有几个PAT(25)

    +
    +

    +字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T);第二个PAT是第3位(P),第4位(A),第6位(T)。

    +

    现给定字符串,问一共可以形成多少个PAT?

    +

    +输入格式: +

    +

    输入只有一行,包含一个字符串,长度不超过105,只包含P、A、T三种字母。 +

    +

    +输出格式: +

    +

    +在一行中输出给定字符串中包含多少个PAT。由于结果可能比较大,只输出对1000000007取余数的结果。 +

    +输入样例:
    +APPAPT
    +
    +输出样例:
    +2
    +
    +
    \ No newline at end of file diff --git a/html/b1041.html b/html/b1041.html new file mode 100644 index 0000000..5cff57e --- /dev/null +++ b/html/b1041.html @@ -0,0 +1,36 @@ + + +

    1041. 考试座位号(15)

    +
    +

    +每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。 +

    +

    +输入格式: +

    +

    +输入第一行给出一个正整数N(<=1000),随后N行,每行给出一个考生的信息:“准考证号 试机座位号 考试座位号”。其中准考证号由14位数字组成,座位从1到N编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。 +

    +

    +考生信息之后,给出一个正整数M(<=N),随后一行中给出M个待查询的试机座位号码,以空格分隔。 +

    +

    +输出格式: +

    +

    +对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用1个空格分隔。 +

    +输入样例:
    +4
    +10120150912233 2 4
    +10120150912119 4 1
    +10120150912126 1 3
    +10120150912002 3 2
    +2
    +3 4
    +
    +输出样例:
    +10120150912002 2
    +10120150912119 1
    +
    +
    \ No newline at end of file diff --git a/html/b1042.html b/html/b1042.html new file mode 100644 index 0000000..f3ff2ff --- /dev/null +++ b/html/b1042.html @@ -0,0 +1,24 @@ + + +

    1042. 字符统计(20)

    +
    +

    +请编写程序,找出一段给定文字中出现最频繁的那个英文字母。

    +

    +输入格式: +

    +

    +输入在一行中给出一个长度不超过1000的字符串。字符串由ASCII码表中任意可见字符及空格组成,至少包含1个英文字母,以回车结束(回车不算在内)。 +

    +

    +输出格式: +

    +

    +在一行中输出出现频率最高的那个英文字母及其出现次数,其间以空格分隔。如果有并列,则输出按字母序最小的那个字母。统计时不区分大小写,输出小写字母。

    +输入样例:
    +This is a simple TEST.  There ARE numbers and other symbols 1&2&3...........
    +
    +输出样例:
    +e 7
    +
    +
    \ No newline at end of file diff --git a/html/b1043.html b/html/b1043.html new file mode 100644 index 0000000..df3a461 --- /dev/null +++ b/html/b1043.html @@ -0,0 +1,24 @@ + + +

    1043. 输出PATest(20)

    +
    +

    +给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按“PATestPATest....”这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按PATest的顺序打印,直到所有字符都被输出。

    +

    +输入格式: +

    +

    +输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。 +

    +

    +输出格式: +

    +

    +在一行中按题目要求输出排序后的字符串。题目保证输出非空。

    +输入样例:
    +redlesPayBestPATTopTeePHPereatitAPPT
    +
    +输出样例:
    +PATestPATestPTetPTePePee
    +
    +
    \ No newline at end of file diff --git a/html/b1044.html b/html/b1044.html new file mode 100644 index 0000000..0ecba4e --- /dev/null +++ b/html/b1044.html @@ -0,0 +1,38 @@ + + +

    1044. 火星数字(20)

    +
    +

    +火星人是以13进制计数的:

    + +

    例如地球人的数字“29”翻译成火星文就是“hel mar”;而火星文“elo nov”对应地球数字“115”。为了方便交流,请你编写程序实现地球和火星数字之间的互译。 +

    +

    +输入格式: +

    +

    +输入第一行给出一个正整数N(<100),随后N行,每行给出一个[0, 169)区间内的数字 —— 或者是地球文,或者是火星文。 +

    +

    +输出格式: +

    +

    +对应输入的每一行,在一行中输出翻译后的另一种语言的数字。

    +输入样例:
    +4
    +29
    +5
    +elo nov
    +tam
    +
    +输出样例:
    +hel mar
    +may
    +115
    +13
    +
    +
    \ No newline at end of file diff --git a/html/b1045.html b/html/b1045.html new file mode 100644 index 0000000..c82d97c --- /dev/null +++ b/html/b1045.html @@ -0,0 +1,36 @@ + + +

    1045. 快速排序(25)

    +
    +

    +著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边。 +给定划分后的N个互不相同的正整数的排列,请问有多少个元素可能是划分前选取的主元?

    +

    例如给定N = 5, 排列是1、3、2、4、5。则:

    +

    +

  • 1的左边没有元素,右边的元素都比它大,所以它可能是主元;
    +
  • 尽管3的左边元素都比它小,但是它右边的2它小,所以它不能是主元;
    +
  • 尽管2的右边元素都比它大,但其左边的3比它大,所以它不能是主元;
    +
  • 类似原因,4和5都可能是主元。
  • +

    因此,有3个元素可能是主元。 +

    +

    +输入格式: +

    +

    +输入在第1行中给出一个正整数N(<= 105); +第2行是空格分隔的N个不同的正整数,每个数不超过109。 +

    +

    +输出格式: +

    +

    在第1行中输出有可能是主元的元素个数;在第2行中按递增顺序输出这些元素,其间以1个空格分隔,行末不得有多余空格。 +

    +输入样例:
    +5
    +1 3 2 4 5
    +
    +输出样例:
    +3
    +1 4 5
    +
    +
    \ No newline at end of file diff --git a/html/b1046.html b/html/b1046.html new file mode 100644 index 0000000..4423431 --- /dev/null +++ b/html/b1046.html @@ -0,0 +1,33 @@ + + +

    1046. 划拳(15)

    +
    +

    +划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。 +

    +

    下面给出甲、乙两人的划拳记录,请你统计他们最后分别喝了多少杯酒。

    +

    +输入格式: +

    +

    +输入第一行先给出一个正整数N(<=100),随后N行,每行给出一轮划拳的记录,格式为:

    +

    甲喊 甲划 乙喊 乙划

    +

    其中“喊”是喊出的数字,“划”是划出的数字,均为不超过100的正整数(两只手一起划)。 +

    +

    +输出格式: +

    +

    +在一行中先后输出甲、乙两人喝酒的杯数,其间以一个空格分隔。

    +输入样例:
    +5
    +8 10 9 12
    +5 10 5 10
    +3 8 5 12
    +12 18 1 13
    +4 16 12 15
    +
    +输出样例:
    +1 2
    +
    +
    \ No newline at end of file diff --git a/html/b1047.html b/html/b1047.html new file mode 100644 index 0000000..b13dbaf --- /dev/null +++ b/html/b1047.html @@ -0,0 +1,35 @@ + + +

    1047. 编程团体赛(20)

    +
    +

    +编程团体赛的规则为:每个参赛队由若干队员组成;所有队员独立比赛;参赛队的成绩为所有队员的成绩和;成绩最高的队获胜。 +

    +

    +现给定所有队员的比赛成绩,请你编写程序找出冠军队。 +

    +

    +输入格式: +

    +

    +输入第一行给出一个正整数N(<=10000),即所有参赛队员总数。随后N行,每行给出一位队员的成绩,格式为:“队伍编号-队员编号 成绩”,其中“队伍编号”为1到1000的正整数,“队员编号”为1到10的正整数,“成绩”为0到100的整数。 +

    +

    +输出格式: +

    +

    +在一行中输出冠军队的编号和总成绩,其间以一个空格分隔。注意:题目保证冠军队是唯一的。 +

    +输入样例:
    +6
    +3-10 99
    +11-5 87
    +102-1 0
    +102-3 100
    +11-9 89
    +3-2 61
    +
    +输出样例:
    +11 176
    +
    +
    \ No newline at end of file diff --git a/html/b1048.html b/html/b1048.html new file mode 100644 index 0000000..46516fb --- /dev/null +++ b/html/b1048.html @@ -0,0 +1,25 @@ + + +

    1048. 数字加密(20)

    +
    +

    +本题要求实现一种数字加密方法。首先固定一个加密用正整数A,对任一正整数B,将其每1位数字与A的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对13取余——这里用J代表10、Q代表11、K代表12;对偶数位,用B的数字减去A的数字,若结果为负数,则再加10。这里令个位为第1位。

    +

    +输入格式: +

    +

    +输入在一行中依次给出A和B,均为不超过100位的正整数,其间以空格分隔。 +

    +

    +输出格式: +

    +

    +在一行中输出加密后的结果。 +

    +输入样例:
    +1234567 368782971
    +
    +输出样例:
    +3695Q8118
    +
    +
    \ No newline at end of file diff --git a/html/b1049.html b/html/b1049.html new file mode 100644 index 0000000..69e8eb7 --- /dev/null +++ b/html/b1049.html @@ -0,0 +1,27 @@ + + +

    1049. 数列的片段和(20)

    +
    +

    +给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段。例如,给定数列{0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) (0.4) 这10个片段。

    +

    给定正整数数列,求出全部片段包含的所有的数之和。如本例中10个片段总和是0.1 + 0.3 + 0.6 + 1.0 + 0.2 + 0.5 + 0.9 + 0.3 + 0.7 + 0.4 = 5.0。

    +

    +输入格式: +

    +

    +输入第一行给出一个不超过105的正整数N,表示数列中数的个数,第二行给出N个不超过1.0的正数,是数列中的数,其间以空格分隔。 +

    +

    +输出格式: +

    +

    +在一行中输出该序列所有片段包含的数之和,精确到小数点后2位。 +

    +输入样例:
    +4
    +0.1 0.2 0.3 0.4 
    +
    +输出样例:
    +5.00
    +
    +
    \ No newline at end of file diff --git a/html/b1050.html b/html/b1050.html new file mode 100644 index 0000000..8d95ee0 --- /dev/null +++ b/html/b1050.html @@ -0,0 +1,30 @@ + + +

    1050. 螺旋矩阵(25)

    +
    +

    +本题要求将给定的N个正整数按非递增的顺序,填入“螺旋矩阵”。所谓“螺旋矩阵”,是指从左上角第1个格子开始,按顺时针螺旋方向填充。要求矩阵的规模为m行n列,满足条件:m*n等于N;m>=n;且m-n取所有可能值中的最小值。 +

    +

    +输入格式: +

    +

    +输入在第1行中给出一个正整数N,第2行给出N个待填充的正整数。所有数字不超过104,相邻数字以空格分隔。 +

    +

    +输出格式: +

    +

    +输出螺旋矩阵。每行n个数字,共m行。相邻数字以1个空格分隔,行末不得有多余空格。 +

    +输入样例:
    +12
    +37 76 20 98 76 42 53 95 60 81 58 93
    +
    +输出样例:
    +98 95 93
    +42 37 81
    +53 20 76
    +58 60 76
    +
    +
    \ No newline at end of file diff --git a/html/b1051.html b/html/b1051.html new file mode 100644 index 0000000..f3a2c34 --- /dev/null +++ b/html/b1051.html @@ -0,0 +1,26 @@ + + +

    1051. 复数乘法 (15)

    +
    +

    +复数可以写成(A + Bi)的常规形式,其中A是实部,B是虚部,i是虚数单位,满足i2 = -1;也可以写成极坐标下的指数形式(R*e(Pi)),其中R是复数模,P是辐角,i是虚数单位,其等价于三角形式 R(cos(P) + isin(P))。

    +

    现给定两个复数的R和P,要求输出两数乘积的常规形式。

    +

    +输入格式: +

    +

    +输入在一行中依次给出两个复数的R1, P1, R2, P2,数字间以空格分隔。 +

    +

    +输出格式: +

    +

    +在一行中按照“A+Bi”的格式输出两数乘积的常规形式,实部和虚部均保留2位小数。注意:如果B是负数,则应该写成“A-|B|i”的形式。 +

    +输入样例:
    +2.3 3.5 5.2 0.4
    +
    +输出样例:
    +-8.68-8.23i
    +
    +
    \ No newline at end of file diff --git a/html/b1052.html b/html/b1052.html new file mode 100644 index 0000000..8969d7e --- /dev/null +++ b/html/b1052.html @@ -0,0 +1,44 @@ + + +

    1052. 卖个萌 (20)

    +
    +

    +萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见,我们假设一个表情符号是按下列格式输出的:

    +
    +[左手]([左眼][口][右眼])[右手]
    +
    +

    +现给出可选用的符号集合,请你按用户的要求输出表情。 +

    +

    +输入格式: +

    +

    +输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号[]内。题目保证每个集合都至少有一个符号,并不超过10个符号;每个符号包含1到4个非空字符。 +

    +

    +之后一行给出一个正整数K,为用户请求的个数。随后K行,每行给出一个用户的符号选择,顺序为左手、左眼、口、右眼、右手——这里只给出符号在相应集合中的序号(从1开始),数字间以空格分隔。 +

    +

    +输出格式: +

    +

    +对每个用户请求,在一行中输出生成的表情。若用户选择的序号不存在,则输出“Are you kidding me? @\/@”。 +

    +输入样例:
    +[╮][╭][o][~\][/~]  [<][>]
    + [╯][╰][^][-][=][>][<][@][⊙]
    +[Д][▽][_][ε][^]  ...
    +4
    +1 1 2 2 2
    +6 8 1 5 5
    +3 3 4 3 3
    +2 10 3 9 3
    +
    +输出样例:
    +╮(╯▽╰)╭
    +<(@Д=)/~
    +o(^ε^)o
    +Are you kidding me? @\/@
    +
    +
    \ No newline at end of file diff --git a/html/b1053.html b/html/b1053.html new file mode 100644 index 0000000..6e57a83 --- /dev/null +++ b/html/b1053.html @@ -0,0 +1,46 @@ + + +

    1053. 住房空置率 (20)

    +
    +

    +在不打扰居民的前提下,统计住房空置率的一种方法是根据每户用电量的连续变化规律进行判断。判断方法如下: +

    + +

    现给定某居民区的住户用电量数据,请你统计“可能空置”的比率和“空置”比率,即以上两种状态的住房占居民区住房总套数的百分比。 +

    +

    +输入格式: +

    +

    +输入第一行给出正整数N(<=1000),为居民区住房总套数;正实数e,即低电量阈值;正整数D,即观察期阈值。随后N行,每行按以下格式给出一套住房的用电量数据: +

    +

    +K E1 E2 ... EK +

    +

    +其中K为观察的天数,Ei为第i天的用电量。 +

    +

    +输出格式: +

    +

    +在一行中输出“可能空置”的比率和“空置”比率的百分比值,其间以一个空格分隔,保留小数点后1位。 +

    +输入样例:
    +5 0.5 10
    +6 0.3 0.4 0.5 0.2 0.8 0.6
    +10 0.0 0.1 0.2 0.3 0.0 0.8 0.6 0.7 0.0 0.5
    +5 0.4 0.3 0.5 0.1 0.7
    +11 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
    +11 2 2 2 1 1 0.1 1 0.1 0.1 0.1 0.1
    +
    +输出样例:
    +40.0% 20.0%
    +
    +

    +(样例解释:第2、3户为“可能空置”,第4户为“空置”,其他户不是空置。) +

    +
    \ No newline at end of file diff --git a/html/b1054.html b/html/b1054.html new file mode 100644 index 0000000..c16e6b3 --- /dev/null +++ b/html/b1054.html @@ -0,0 +1,39 @@ + + +

    1054. 求平均值 (20)

    +
    +

    +本题的基本要求非常简单:给定N个实数,计算它们的平均值。但复杂的是有些输入数据可能是非法的。一个“合法”的输入是[-1000,1000]区间内的实数,并且最多精确到小数点后2位。当你计算平均值的时候,不能把那些非法的数据算在内。

    +

    +输入格式: +

    +

    +输入第一行给出正整数N(<=100)。随后一行给出N个实数,数字间以一个空格分隔。 +

    +

    +输出格式: +

    +

    +对每个非法输入,在一行中输出“ERROR: X is not a legal number”,其中X是输入。最后在一行中输出结果:“The average of K numbers is Y”,其中K是合法输入的个数,Y是它们的平均值,精确到小数点后2位。如果平均值无法计算,则用“Undefined”替换Y。如果K为1,则输出“The average of 1 number is Y”。 +

    +输入样例1:
    +7
    +5 -3.2 aaa 9999 2.3.4 7.123 2.35
    +
    +输出样例1:
    +ERROR: aaa is not a legal number
    +ERROR: 9999 is not a legal number
    +ERROR: 2.3.4 is not a legal number
    +ERROR: 7.123 is not a legal number
    +The average of 3 numbers is 1.38
    +
    +输入样例2:
    +2
    +aaa -9999
    +
    +输出样例2:
    +ERROR: aaa is not a legal number
    +ERROR: -9999 is not a legal number
    +The average of 0 numbers is Undefined
    +
    +
    \ No newline at end of file diff --git a/html/b1055.html b/html/b1055.html new file mode 100644 index 0000000..afedfbd --- /dev/null +++ b/html/b1055.html @@ -0,0 +1,45 @@ + + +

    1055. 集体照 (25)

    +
    +

    +拍集体照时队形很重要,这里对给定的N个人K排的队形设计排队规则如下: +

    + +

    现给定一组拍照人,请编写程序输出他们的队形。

    +

    +输入格式: +

    +

    每个输入包含1个测试用例。每个测试用例第1行给出两个正整数N(<=10000,总人数)和K(<=10,总排数)。随后N行,每行给出一个人的名字(不包含空格、长度不超过8个英文字母)和身高([30, 300]区间内的整数)。 +

    +

    +输出格式: +

    +

    +输出拍照的队形。即K排人名,其间以空格分隔,行末不得有多余空格。注意:假设你面对拍照者,后排的人输出在上方,前排输出在下方。 +

    +输入样例:
    +10 3
    +Tom 188
    +Mike 170
    +Eva 168
    +Tim 160
    +Joe 190
    +Ann 168
    +Bob 175
    +Nick 186
    +Amy 160
    +John 159
    +
    +输出样例:
    +Bob Tom Joe Nick
    +Ann Mike Eva
    +Tim Amy John
    +
    +
    \ No newline at end of file diff --git a/html/b1056.html b/html/b1056.html new file mode 100644 index 0000000..4dfe5d5 --- /dev/null +++ b/html/b1056.html @@ -0,0 +1,25 @@ + + +

    1056. 组合数的和(15)

    +
    +

    +给定N个非0的个位数字,用其中任意2个数字都可以组合成1个2位的数字。要求所有可能组合出来的2位数字的和。例如给定2、5、8,则可以组合出:25、28、52、58、82、85,它们的和为330。

    +

    +输入格式: +

    +

    +输入在一行中先给出N(1<N<10),随后是N个不同的非0个位数字。数字间以空格分隔。 +

    +

    +输出格式: +

    +

    +输出所有可能组合出来的2位数字的和。 +

    +输入样例:
    +3 2 8 5
    +
    +输出样例:
    +330
    +
    +
    \ No newline at end of file diff --git a/html/b1057.html b/html/b1057.html new file mode 100644 index 0000000..c61cc44 --- /dev/null +++ b/html/b1057.html @@ -0,0 +1,25 @@ + + +

    1057. 数零壹(20)

    +
    +

    给定一串长度不超过105的字符串,本题要求你将其中所有英文字母的序号(字母a-z对应序号1-26,不分大小写)相加,得到整数N,然后再分析一下N的二进制表示中有多少0、多少1。例如给定字符串“PAT (Basic)”,其字母序号之和为:16+1+20+2+1+19+9+3=71,而71的二进制是1000111,即有3个0、4个1。 +

    +

    +输入格式: +

    +

    +输入在一行中给出长度不超过105、以回车结束的字符串。 +

    +

    +输出格式: +

    +

    +在一行中先后输出0的个数和1的个数,其间以空格分隔。 +

    +输入样例:
    +PAT (Basic)
    +
    +输出样例:
    +3 4
    +
    +
    \ No newline at end of file diff --git a/html/b1058.html b/html/b1058.html new file mode 100644 index 0000000..d4f8dc0 --- /dev/null +++ b/html/b1058.html @@ -0,0 +1,35 @@ + + +

    1058. 选择题(20)

    +
    +

    批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。 +

    +

    +输入格式: +

    +

    +输入在第一行给出两个正整数N(<=1000)和M(<=100),分别是学生人数和多选题的个数。随后M行,每行顺次给出一道题的满分值(不超过5的正整数)、选项个数(不少于2且不超过5的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母a开始顺次排列。各项间以1个空格分隔。最后N行,每行给出一个学生的答题情况,其每题答案格式为“(选中的选项个数 选项1 ……)”,按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。 +

    +

    +输出格式: +

    +

    +按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从1开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出“Too simple”。 +

    +输入样例:
    +3 4 
    +3 4 2 a c
    +2 5 1 b
    +5 3 2 b c
    +1 5 4 a b d e
    +(2 a c) (2 b d) (2 a c) (3 a b e)
    +(2 a c) (1 b) (2 a b) (4 a b d e)
    +(2 b d) (1 e) (2 b c) (4 a b c d)
    +
    +输出样例:
    +3
    +6
    +5
    +2 2 3 4
    +
    +
    \ No newline at end of file diff --git a/html/b1059.html b/html/b1059.html new file mode 100644 index 0000000..5be1bac --- /dev/null +++ b/html/b1059.html @@ -0,0 +1,51 @@ + + +

    1059. C语言竞赛(20)

    +
    +

    +C语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛。既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽: +

    +

    +0. 冠军将赢得一份“神秘大奖”(比如很巨大的一本学生研究论文集……)。
    +1. 排名为素数的学生将赢得最好的奖品 —— 小黄人玩偶!
    +2. 其他人将得到巧克力。

    +

    +给定比赛的最终排名以及一系列参赛者的ID,你要给出这些参赛者应该获得的奖品。 +

    +

    +输入格式: +

    +

    +输入第一行给出一个正整数N(<=10000),是参赛者人数。随后N行给出最终排名,每行按排名顺序给出一位参赛者的ID(4位数字组成)。接下来给出一个正整数K以及K个需要查询的ID。 +

    +

    +输出格式: +

    +

    +对每个要查询的ID,在一行中输出“ID: 奖品”,其中奖品或者是“Mystery Award”(神秘大奖)、或者是“Minion”(小黄人)、或者是“Chocolate”(巧克力)。如果所查ID根本不在排名里,打印“Are you kidding?”(耍我呢?)。如果该ID已经查过了(即奖品已经领过了),打印“ID: Checked”(不能多吃多占)。 +

    +输入样例:
    +6
    +1111
    +6666
    +8888
    +1234
    +5555
    +0001
    +6
    +8888
    +0001
    +1111
    +2222
    +8888
    +2222
    +
    +输出样例:
    +8888: Minion
    +0001: Chocolate
    +1111: Mystery Award
    +2222: Are you kidding?
    +8888: Checked
    +2222: Are you kidding?
    +
    +
    \ No newline at end of file diff --git a/html/b1060.html b/html/b1060.html new file mode 100644 index 0000000..5d42010 --- /dev/null +++ b/html/b1060.html @@ -0,0 +1,29 @@ + + +

    1060. 爱丁顿数(25)

    +
    +

    +英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数”E,即满足有E天骑车超过E英里的最大整数E。据说爱丁顿自己的E等于87。 +

    +

    +现给定某人N天的骑车距离,请你算出对应的爱丁顿数E(<=N)。 +

    +

    +输入格式: +

    +

    +输入第一行给出一个正整数N(<=105),即连续骑车的天数;第二行给出N个非负整数,代表每天的骑车距离。 +

    +

    +输出格式: +

    +

    +在一行中给出N天的爱丁顿数。

    +输入样例:
    +10
    +6 7 6 9 3 10 8 2 7 8
    +
    +输出样例:
    +6
    +
    +
    \ No newline at end of file diff --git a/html/b1061.html b/html/b1061.html new file mode 100644 index 0000000..e1d02b5 --- /dev/null +++ b/html/b1061.html @@ -0,0 +1,32 @@ + + +

    1061. 判断题(15)

    +
    +

    判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分。 +

    +

    +输入格式: +

    +

    +输入在第一行给出两个不超过100的正整数N和M,分别是学生人数和判断题数量。第二行给出M个不超过5的正整数,是每道题的满分值。第三行给出每道题对应的正确答案,0代表“非”,1代表“是”。随后N行,每行给出一个学生的解答。数字间均以空格分隔。 +

    +

    +输出格式: +

    +

    +按照输入的顺序输出每个学生的得分,每个分数占一行。 +

    +输入样例:
    +3 6
    +2 1 3 3 4 5
    +0 0 1 0 1 1
    +0 1 1 0 0 1
    +1 0 1 0 1 0
    +1 1 0 0 1 1
    +
    +输出样例:
    +13
    +11
    +12
    +
    +
    \ No newline at end of file diff --git a/html/b1062.html b/html/b1062.html new file mode 100644 index 0000000..f17093d --- /dev/null +++ b/html/b1062.html @@ -0,0 +1,27 @@ + + +

    1062. 最简分数(20)

    +
    +

    一个分数一般写成两个整数相除的形式:N/M,其中M不为0。最简分数是指分子和分母没有公约数的分数表示形式。 +

    +

    现给定两个不相等的正分数 N1/M1 和 N2/M2,要求你按从小到大的顺序列出它们之间分母为K的最简分数。 +

    +

    +输入格式: +

    +

    +输入在一行中按N/M的格式给出两个正分数,随后是一个正整数分母K,其间以空格分隔。题目保证给出的所有整数都不超过1000。 +

    +

    +输出格式: +

    +

    +在一行中按N/M的格式列出两个给定分数之间分母为K的所有最简分数,按从小到大的顺序,其间以1个空格分隔。行首尾不得有多余空格。题目保证至少有1个输出。 +

    +输入样例:
    +7/18 13/20 12
    +
    +输出样例:
    +5/12 7/12
    +
    +
    \ No newline at end of file diff --git a/html/b1063.html b/html/b1063.html new file mode 100644 index 0000000..2df18f3 --- /dev/null +++ b/html/b1063.html @@ -0,0 +1,32 @@ + + +

    1063. 计算谱半径(20)

    +
    +

    +在数学中,矩阵的“谱半径”是指其特征值的模集合的上确界。换言之,对于给定的n个复数空间的特征值{a1+b1i, ..., an+bni},它们的模为实部与虚部的平方和的开方,而“谱半径”就是最大模。 +

    +

    现在给定一些复数空间的特征值,请你计算并输出这些特征值的谱半径。

    +

    +输入格式: +

    +

    +输入第一行给出正整数N(<= 10000)是输入的特征值的个数。随后N行,每行给出1个特征值的实部和虚部,其间以空格分隔。注意:题目保证实部和虚部均为绝对值不超过1000的整数。 +

    +

    +输出格式: +

    +

    +在一行中输出谱半径,四舍五入保留小数点后2位。 +

    +输入样例:
    +5
    +0 1
    +2 0
    +-1 0
    +3 3
    +0 -3
    +
    +输出样例:
    +4.24
    +
    +
    \ No newline at end of file diff --git a/html/b1064.html b/html/b1064.html new file mode 100644 index 0000000..47294a3 --- /dev/null +++ b/html/b1064.html @@ -0,0 +1,27 @@ + + +

    1064. 朋友数(20)

    +
    +

    +如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”。例如123和51就是朋友数,因为1+2+3 = 5+1 = 6,而6就是它们的朋友证号。给定一些整数,要求你统计一下它们中有多少个不同的朋友证号。注意:我们默认一个整数自己是自己的朋友。

    +

    +输入格式: +

    +

    +输入第一行给出正整数N。随后一行给出N个正整数,数字间以空格分隔。题目保证所有数字小于104。 +

    +

    +输出格式: +

    +

    +首先第一行输出给定数字中不同的朋友证号的个数;随后一行按递增顺序输出这些朋友证号,数字间隔一个空格,且行末不得有多余空格。 +

    +输入样例:
    +8
    +123 899 51 998 27 33 36 12
    +
    +输出样例:
    +4
    +3 6 9 26
    +
    +
    \ No newline at end of file diff --git a/html/b1065.html b/html/b1065.html new file mode 100644 index 0000000..e8ce337 --- /dev/null +++ b/html/b1065.html @@ -0,0 +1,32 @@ + + +

    1065. 单身狗(25)

    +
    +

    +“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱。 +

    +

    +输入格式: +

    +

    +输入第一行给出一个正整数N(<=50000),是已知夫妻/伴侣的对数;随后N行,每行给出一对夫妻/伴侣——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空格分隔;之后给出一个正整数M(<=10000),为参加派对的总人数;随后一行给出这M位客人的ID,以空格分隔。题目保证无人重婚或脚踩两条船。 +

    +

    +输出格式: +

    +

    +首先第一行输出落单客人的总人数;随后第二行按ID递增顺序列出落单的客人。ID间用1个空格分隔,行的首尾不得有多余空格。 +

    +输入样例:
    +3
    +11111 22222
    +33333 44444
    +55555 66666
    +7
    +55555 44444 10000 88888 22222 11111 23333
    +
    +输出样例:
    +5
    +10000 23333 44444 55555 88888
    +
    +
    \ No newline at end of file diff --git a/html/b1066.html b/html/b1066.html new file mode 100644 index 0000000..bcc518f --- /dev/null +++ b/html/b1066.html @@ -0,0 +1,29 @@ + + +

    1066. 图像过滤(15)

    +
    +

    图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来。现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换。

    +

    +输入格式: +

    +

    +输入在第一行给出一幅图像的分辨率,即两个正整数M和N(0 < M, N <= 500),另外是待过滤的灰度值区间端点A和B(0 <= A < B <= 255)、以及指定的替换灰度值。随后M行,每行给出N个像素点的灰度值,其间以空格分隔。所有灰度值都在[0, 255]区间内。 +

    +

    +输出格式: +

    +

    +输出按要求过滤后的图像。即输出M行,每行N个像素灰度值,每个灰度值占3位(例如黑色要显示为000),其间以一个空格分隔。行首尾不得有多余空格。 +

    +输入样例:
    +3 5 100 150 0
    +3 189 254 101 119
    +150 233 151 99 100
    +88 123 149 0 255
    +
    +输出样例:
    +003 189 254 000 000
    +000 233 151 099 000
    +088 000 000 000 255
    +
    +
    \ No newline at end of file diff --git a/html/b1067.html b/html/b1067.html new file mode 100644 index 0000000..9512060 --- /dev/null +++ b/html/b1067.html @@ -0,0 +1,46 @@ + + +

    1067. 试密码(20)

    +
    +

    当你试图登录某个系统却忘了密码时,系统一般只会允许你尝试有限多次,当超出允许次数时,账号就会被锁死。本题就请你实现这个小功能。 +

    +

    +输入格式: +

    +

    +输入在第一行给出一个密码(长度不超过20的、不包含空格、Tab、回车的非空字符串)和一个正整数N(<= 10),分别是正确的密码和系统允许尝试的次数。随后每行给出一个以回车结束的非空字符串,是用户尝试输入的密码。输入保证至少有一次尝试。当读到一行只有单个#字符时,输入结束,并且这一行不是用户的输入。 +

    +

    +输出格式: +

    +

    +对用户的每个输入,如果是正确的密码且尝试次数不超过N,则在一行中输出“Welcome in”,并结束程序;如果是错误的,则在一行中按格式输出“Wrong password: 用户输入的错误密码”;当错误尝试达到N次时,再输出一行“Account locked”,并结束程序。 +

    +输入样例1:
    +Correct%pw 3
    +correct%pw
    +Correct@PW
    +whatisthepassword!
    +Correct%pw
    +#
    +
    +输出样例1:
    +Wrong password: correct%pw
    +Wrong password: Correct@PW
    +Wrong password: whatisthepassword!
    +Account locked
    +
    +输入样例2:
    +cool@gplt 3
    +coolman@gplt
    +coollady@gplt
    +cool@gplt
    +try again
    +#
    +
    +输出样例2:
    +Wrong password: coolman@gplt
    +Wrong password: coollady@gplt
    +Welcome in
    +
    +
    \ No newline at end of file diff --git a/html/b1068.html b/html/b1068.html new file mode 100644 index 0000000..bc73fdb --- /dev/null +++ b/html/b1068.html @@ -0,0 +1,51 @@ + + +

    1068. 万绿丛中一点红(20)

    +
    +

    对于计算机而言,颜色不过是像素点对应的一个24位的数值。现给定一幅分辨率为MxN的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围8个相邻像素的颜色差充分大。 +

    +

    +输入格式: +

    +

    +输入第一行给出三个正整数,分别是M和N(<= 1000),即图像的分辨率;以及TOL,是所求像素点与相邻点的颜色差阈值,色差超过TOL的点才被考虑。随后N行,每行给出M个像素的颜色值,范围在[0, 224)内。所有同行数字间用空格或TAB分开。 +

    +

    +输出格式: +

    +

    +在一行中按照“(x, y): color”的格式输出所求像素点的位置以及颜色值,其中位置x和y分别是该像素在图像矩阵中的列、行编号(从1开始编号)。如果这样的点不唯一,则输出“Not Unique”;如果这样的点不存在,则输出“Not Exist”。 +

    +输入样例1:
    +8 6 200
    +0 	 0 	  0 	   0	    0 	     0 	      0        0
    +65280 	 65280    65280    16711479 65280    65280    65280    65280
    +16711479 65280    65280    65280    16711680 65280    65280    65280
    +65280 	 65280    65280    65280    65280    65280    165280   165280
    +65280 	 65280 	  16777015 65280    65280    165280   65480    165280
    +16777215 16777215 16777215 16777215 16777215 16777215 16777215 16777215
    +
    +输出样例1:
    +(5, 3): 16711680
    +
    +输入样例2:
    +4 5 2
    +0 0 0 0
    +0 0 3 0
    +0 0 0 0
    +0 5 0 0
    +0 0 0 0
    +
    +输出样例2:
    +Not Unique
    +
    +输入样例3:
    +3 3 5
    +1 2 3
    +3 4 5
    +5 6 7
    +
    +输出样例3:
    +Not Exist
    +
    +
    \ No newline at end of file diff --git a/html/b1069.html b/html/b1069.html new file mode 100644 index 0000000..eb4dd14 --- /dev/null +++ b/html/b1069.html @@ -0,0 +1,48 @@ + + +

    1069. 微博转发抽奖(20)

    +
    +

    +小明PAT考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔N个人就发出一个红包。请你编写程序帮助他确定中奖名单。 +

    +

    +输入格式: +

    +

    +输入第一行给出三个正整数M(<= 1000)、N和S,分别是转发的总量、小明决定的中奖间隔、以及第一位中奖者的序号(编号从1开始)。随后M行,顺序给出转发微博的网友的昵称(不超过20个字符、不包含空格回车的非空字符串)。 +

    +

    +注意:可能有人转发多次,但不能中奖多次。所以如果处于当前中奖位置的网友已经中过奖,则跳过他顺次取下一位。 +

    +

    +输出格式: +

    +

    +按照输入的顺序输出中奖名单,每个昵称占一行。如果没有人中奖,则输出“Keep going...”。 +

    +输入样例1:
    +9 3 2
    +Imgonnawin!
    +PickMe
    +PickMeMeMeee
    +LookHere
    +Imgonnawin!
    +TryAgainAgain
    +TryAgainAgain
    +Imgonnawin!
    +TryAgainAgain
    +
    +输出样例1:
    +PickMe
    +Imgonnawin!
    +TryAgainAgain
    +
    +输入样例2:
    +2 3 5
    +Imgonnawin!
    +PickMe
    +
    +输出样例2:
    +Keep going...
    +
    +
    \ No newline at end of file diff --git a/html/b1070.html b/html/b1070.html new file mode 100644 index 0000000..3773f23 --- /dev/null +++ b/html/b1070.html @@ -0,0 +1,25 @@ + + +

    1070. 结绳(25)

    +
    +

    给定一段一段的绳子,你需要把它们串成一条绳。每次串连的时候,是把两段绳子对折,再如下图所示套接在一起。这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段绳子串连。每次串连后,原来两段绳子的长度就会减半。

    +
    +

    +给定N段绳子的长度,你需要找出它们能串成的绳子的最大长度。 +

    +

    +输入格式: +

    +

    每个输入包含1个测试用例。每个测试用例第1行给出正整数N (2 <= N <= 104);第2行给出N个正整数,即原始绳段的长度,数字间以空格分隔。所有整数都不超过104。

    +

    +输出格式: +

    +

    在一行中输出能够串成的绳子的最大长度。结果向下取整,即取为不超过最大长度的最近整数。

    +输入样例:
    +8
    +10 15 12 3 4 13 1 15
    +
    +输出样例:
    +14
    +
    +
    \ No newline at end of file diff --git a/html/b1071.html b/html/b1071.html new file mode 100644 index 0000000..50695d2 --- /dev/null +++ b/html/b1071.html @@ -0,0 +1,59 @@ + + +

    1071. 小赌怡情(15)

    +
    +

    常言道“小赌怡情”。这是一个很简单的小游戏:首先由计算机给出第一个整数;然后玩家下注赌第二个整数将会比第一个数大还是小;玩家下注t个筹码后,计算机给出第二个数。若玩家猜对了,则系统奖励玩家t个筹码;否则扣除玩家t个筹码。 +

    +

    +注意:玩家下注的筹码数不能超过自己帐户上拥有的筹码数。当玩家输光了全部筹码后,游戏就结束。 +

    +

    +输入格式: +

    +

    +输入在第一行给出2个正整数T和K(<=100),分别是系统在初始状态下赠送给玩家的筹码数、以及需要处理的游戏次数。随后K行,每行对应一次游戏,顺序给出4个数字: +

    +

    +n1 b t n2 +

    +

    +其中n1和n2是计算机先后给出的两个[0, 9]内的整数,保证两个数字不相等。b为0表示玩家赌“小”,为1表示玩家赌“大”。t表示玩家下注的筹码数,保证在整型范围内。 +

    +

    +输出格式: +

    +

    +对每一次游戏,根据下列情况对应输出(其中t是玩家下注量,x是玩家当前持有的筹码量): +

    + +输入样例1:
    +100 4
    +8 0 100 2
    +3 1 50 1
    +5 1 200 6
    +7 0 200 8
    +
    +输出样例1:
    +Win 100!  Total = 200.
    +Lose 50.  Total = 150.
    +Not enough tokens.  Total = 150.
    +Not enough tokens.  Total = 150.
    +
    +输入样例2:
    +100 4
    +8 0 100 2
    +3 1 200 1
    +5 1 200 6
    +7 0 200 8
    +
    +输出样例2:
    +Win 100!  Total = 200.
    +Lose 200.  Total = 0.
    +Game Over.
    +
    +
    \ No newline at end of file diff --git a/html/b1072.html b/html/b1072.html new file mode 100644 index 0000000..d9958cb --- /dev/null +++ b/html/b1072.html @@ -0,0 +1,41 @@ + + +

    1072. 开学寄语(20)

    +
    +

    下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其QQ,封其电脑,夺其手机,收其ipad,断其wifi,使其百无聊赖,然后,净面、理发、整衣,然后思过、读书、锻炼、明智、开悟、精进。而后必成大器也! +

    +
    +

    +本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器。 +

    +

    +输入格式: +

    +

    +输入第一行给出两个正整数N(<= 1000)和M(<= 6),分别是学生人数和需要被查缴的物品种类数。第二行给出M个需要被查缴的物品编号,其中编号为4位数字。随后N行,每行给出一位学生的姓名缩写(由1-4个大写英文字母组成)、个人物品数量K(0 <= K <= 10)、以及K个物品的编号。 +

    +

    +输出格式: +

    +

    +顺次检查每个学生携带的物品,如果有需要被查缴的物品存在,则按以下格式输出该生的信息和其需要被查缴的物品的信息(注意行末不得有多余空格): +

    +
    姓名缩写: 物品编号1 物品编号2 ……
    +
    +

    最后一行输出存在问题的学生的总人数和被查缴物品的总数。 +

    +输入样例:
    +4 2
    +2333 6666
    +CYLL 3 1234 2345 3456
    +U 4 9966 6666 8888 6666
    +GG 2 2333 7777
    +JJ 3 0012 6666 2333
    +
    +输出样例:
    +U: 6666 6666
    +GG: 2333
    +JJ: 6666 2333
    +3 5
    +
    +
    \ No newline at end of file diff --git a/html/b1073.html b/html/b1073.html new file mode 100644 index 0000000..6d85e0d --- /dev/null +++ b/html/b1073.html @@ -0,0 +1,49 @@ + + +

    1073. 多选题常见计分法(20)

    +
    +

    批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到50%分数;如果考生选择了任何一个错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选项错的人最多。 +

    +

    +输入格式: +

    +

    +输入在第一行给出两个正整数N(<=1000)和M(<=100),分别是学生人数和多选题的个数。随后M行,每行顺次给出一道题的满分值(不超过5的正整数)、选项个数(不少于2且不超过5的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母a开始顺次排列。各项间以1个空格分隔。最后N行,每行给出一个学生的答题情况,其每题答案格式为“(选中的选项个数 选项1 ……)”,按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。 +

    +

    +输出格式: +

    +

    +按照输入的顺序给出每个学生的得分,每个分数占一行,输出小数点后1位。最后输出错得最多的题目选项的信息,格式为:“错误次数 题目编号(题目按照输入的顺序从1开始编号)-选项号”。如果有并列,则每行一个选项,按题目编号递增顺序输出;再并列则按选项号递增顺序输出。行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出“Too simple”。 +

    +输入样例1:
    +3 4 
    +3 4 2 a c
    +2 5 1 b
    +5 3 2 b c
    +1 5 4 a b d e
    +(2 a c) (3 b d e) (2 a c) (3 a b e)
    +(2 a c) (1 b) (2 a b) (4 a b d e)
    +(2 b d) (1 e) (1 c) (4 a b c d)
    +
    +输出样例1:
    +3.5
    +6.0
    +2.5
    +2 2-e
    +2 3-a
    +2 3-b
    +
    +输入样例2:
    +2 2 
    +3 4 2 a c
    +2 5 1 b
    +(2 a c) (1 b)
    +(2 a c) (1 b)
    +
    +输出样例2:
    +5.0
    +5.0
    +Too simple
    +
    +
    \ No newline at end of file diff --git a/html/b1074.html b/html/b1074.html new file mode 100644 index 0000000..baea2a1 --- /dev/null +++ b/html/b1074.html @@ -0,0 +1,31 @@ + + +

    1074. 宇宙无敌加法器(20)

    +
    +

    地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的。而在PAT星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”。每个PAT星人都必须熟记各位数字的进制表,例如“……0527”就表示最低位是7进制数、第2位是2进制数、第3位是5进制数、第4位是10进制数,等等。每一位的进制d或者是0(表示十进制)、或者是[2,9]区间内的整数。理论上这个进制表应该包含无穷多位数字,但从实际应用出发,PAT星人通常只需要记住前20位就够用了,以后各位默认为10进制。 +

    +

    +在这样的数字系统中,即使是简单的加法运算也变得不简单。例如对应进制表“0527”,该如何计算“6203+415”呢?我们得首先计算最低位:3+5=8;因为最低位是7进制的,所以我们得到1和1个进位。第2位是:0+1+1(进位)=2;因为此位是2进制的,所以我们得到0和1个进位。第3位是:2+4+1(进位)=7;因为此位是5进制的,所以我们得到2和1个进位。第4位是:6+1(进位)=7;因为此位是10进制的,所以我们就得到7。最后我们得到:6203+415=7201。 +

    +

    +输入格式: +

    +

    +输入首先在第一行给出一个N位的进制表(0 < N <=20),以回车结束。 +随后两行,每行给出一个不超过N位的非负的PAT数。 +

    +

    +输出格式: +

    +

    +在一行中输出两个PAT数之和。 +

    +输入样例:
    +30527
    +06203
    +415
    +
    +输出样例:
    +7201
    +
    +
    \ No newline at end of file diff --git a/html/b1075.html b/html/b1075.html new file mode 100644 index 0000000..69743dc --- /dev/null +++ b/html/b1075.html @@ -0,0 +1,40 @@ + + +

    1075. 链表元素分类(25)

    +
    +

    给定一个单链表,请编写程序将链表元素进行分类排列,使得所有负值元素都排在非负值元素的前面,而[0, K]区间内的元素都排在大于K的元素前面。但每一类内部元素的顺序是不能改变的。例如:给定链表为 18→7→-4→0→5→-6→10→11→-2,K为10,则输出应该为 -4→-6→-2→7→0→5→10→18→11。

    +

    +输入格式: +

    +

    每个输入包含1个测试用例。每个测试用例第1行给出:第1个结点的地址;结点总个数,即正整数N (<= 105);以及正整数K (<=1000)。结点的地址是5位非负整数,NULL地址用-1表示。

    +

    接下来有N行,每行格式为:

    +

    Address Data Next

    +

    其中Address是结点地址;Data是该结点保存的数据,为[-105, 105]区间内的整数;Next是下一结点的地址。题目保证给出的链表不为空。

    +

    +输出格式: +

    +

    对每个测试用例,按链表从头到尾的顺序输出重排后的结果链表,其上每个结点占一行,格式与输入相同。

    +输入样例:
    +00100 9 10
    +23333 10 27777
    +00000 0 99999
    +00100 18 12309
    +68237 -6 23333
    +33218 -4 00000
    +48652 -2 -1
    +99999 5 68237
    +27777 11 48652
    +12309 7 33218
    +
    +输出样例:
    +33218 -4 68237
    +68237 -6 48652
    +48652 -2 12309
    +12309 7 00000
    +00000 0 99999
    +99999 5 23333
    +23333 10 00100
    +00100 18 27777
    +27777 11 -1
    +
    +
    \ No newline at end of file diff --git a/html/b1076.html b/html/b1076.html new file mode 100644 index 0000000..840aebd --- /dev/null +++ b/html/b1076.html @@ -0,0 +1,34 @@ + + +

    1076. Wifi密码 (15)

    +
    +

    下面是微博上流传的一张照片:“各位亲爱的同学们,鉴于大家有时需要使用wifi,又怕耽误亲们的学习,现将wifi密码设置为下列数学题答案:A-1;B-2;C-3;D-4;请同学们自己作答,每两日一换。谢谢合作!!~”—— 老师们为了促进学生学习也是拼了…… 本题就要求你写程序把一系列题目的答案按照卷子上给出的对应关系翻译成wifi的密码。这里简单假设每道选择题都有4个选项,有且只有1个正确答案。 +

    +
    +

    +输入格式: +

    +

    +输入第一行给出一个正整数N(<= 100),随后N行,每行按照“编号-答案”的格式给出一道题的4个选项,“T”表示正确选项,“F”表示错误选项。选项间用空格分隔。 +

    +

    +输出格式: +

    +

    +在一行中输出wifi密码。 +

    +输入样例:
    +8
    +A-T B-F C-F D-F
    +C-T B-F A-F D-F
    +A-F D-F C-F B-T
    +B-T A-F C-F D-F
    +B-F D-T A-F C-F
    +A-T C-F B-F D-F
    +D-T B-F C-F A-F
    +C-T A-F B-F D-F
    +
    +输出样例:
    +13224143
    +
    +
    \ No newline at end of file diff --git a/html/b1077.html b/html/b1077.html new file mode 100644 index 0000000..e932f5d --- /dev/null +++ b/html/b1077.html @@ -0,0 +1,36 @@ + + +

    1077. 互评成绩计算 (20)

    +
    +

    在浙大的计算机专业课中,经常有互评分组报告这个环节。一个组上台介绍自己的工作,其他组在台下为其表现评分。最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个最高分和一个最低分,剩下的分数取平均分记为 G1;老师给这个组的评分记为 G2。该组得分为 (G1+G2)/2,最后结果四舍五入后保留整数分。本题就要求你写个程序帮助老师计算每个组的互评成绩。 +

    +

    +输入格式: +

    +

    +输入第一行给出两个正整数N(> 3)和M,分别是分组数和满分,均不超过100。随后N行,每行给出该组得到的N个分数(均保证为整型范围内的整数),其中第1个是老师给出的评分,后面 N-1 个是其他组给的评分。合法的输入应该是[0, M]区间内的整数,若不在合法区间内,则该分数须被忽略。题目保证老师的评分都是合法的,并且每个组至少会有3个来自同学的合法评分。 +

    +

    +输出格式: +

    +

    +为每个组输出其最终得分。每个得分占一行。 +

    +输入样例:
    +6 50
    +42 49 49 35 38 41
    +36 51 50 28 -1 30
    +40 36 41 33 47 49
    +30 250 -25 27 45 31
    +48 0 0 50 50 1234
    +43 41 36 29 42 29
    +
    +输出样例:
    +42
    +33
    +41
    +31
    +37
    +39
    +
    +
    \ No newline at end of file diff --git a/html/b1078.html b/html/b1078.html new file mode 100644 index 0000000..3b753ad --- /dev/null +++ b/html/b1078.html @@ -0,0 +1,39 @@ + + +

    1078. 字符串压缩与解压 (20)

    +
    +

    文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示。例如 ccccc 就用 5c 来表示。如果字符没有重复,就原样输出。例如 aba 压缩后仍然是 aba。 +

    +

    +解压方法就是反过来,把形如 5c 这样的表示恢复为 ccccc。 +

    +

    +本题需要你根据压缩或解压的要求,对给定字符串进行处理。这里我们简单地假设原始字符串是完全由英文字母和空格组成的非空字符串。 +

    +

    +输入格式: +

    +

    +输入第一行给出一个字符,如果是 C 就表示下面的字符串需要被压缩;如果是 D 就表示下面的字符串需要被解压。第二行给出需要被压缩或解压的不超过1000个字符的字符串,以回车结尾。题目保证字符重复个数在整型范围内,且输出文件不超过1MB。 +

    +

    +输出格式: +

    +

    +根据要求压缩或解压字符串,并在一行中输出结果。 +

    +输入样例 1:
    +C
    +TTTTThhiiiis isssss a   tesssst CAaaa as
    +
    +输出样例 1:
    +5T2h4is i5s a3 te4st CA3a as
    +
    +输入样例 2:
    +D
    +5T2h4is i5s a3 te4st CA3a as10Z
    +
    +输出样例 2:
    +TTTTThhiiiis isssss a   tesssst CAaaa asZZZZZZZZZZ
    +
    +
    \ No newline at end of file diff --git a/html/b1079.html b/html/b1079.html new file mode 100644 index 0000000..d5e95a4 --- /dev/null +++ b/html/b1079.html @@ -0,0 +1,54 @@ + + +

    1079. 延迟的回文数 (20)

    +
    +

    给定一个 k+1 位的正整数 N,写成 ak...a1a0 的形式,其中对所有 i 有 0 <= ai < 10 且 ak > 0。N 被称为一个回文数,当且仅当对所有 i 有 ai = ak-i。零也被定义为一个回文数。 +

    +

    +非回文数也可以通过一系列操作变出回文数。首先将该数字逆转,再将逆转数与该数相加,如果和还不是一个回文数,就重复这个逆转再相加的操作,直到一个回文数出现。如果一个非回文数可以变出回文数,就称这个数为延迟的回文数。(定义翻译自 https://en.wikipedia.org/wiki/Palindromic_number) +

    +

    +给定任意一个正整数,本题要求你找到其变出的那个回文数。 +

    +

    +输入格式: +

    +

    +输入在一行中给出一个不超过1000位的正整数。 +

    +

    +输出格式: +

    +

    +对给定的整数,一行一行输出其变出回文数的过程。每行格式如下 +

    +A + B = C
    +
    +

    +其中A是原始的数字,B是A的逆转数,C是它们的和。A从输入的整数开始。重复操作直到C在10步以内变成回文数,这时在一行中输出“C is a palindromic number.”;或者如果10步都没能得到回文数,最后就在一行中输出“Not found in 10 iterations.”。 +

    +输入样例 1:
    +97152
    +
    +输出样例 1:
    +97152 + 25179 = 122331
    +122331 + 133221 = 255552
    +255552 is a palindromic number.
    +
    +输入样例 2:
    +196
    +
    +输出样例 2:
    +196 + 691 = 887
    +887 + 788 = 1675
    +1675 + 5761 = 7436
    +7436 + 6347 = 13783
    +13783 + 38731 = 52514
    +52514 + 41525 = 94039
    +94039 + 93049 = 187088
    +187088 + 880781 = 1067869
    +1067869 + 9687601 = 10755470
    +10755470 + 07455701 = 18211171
    +Not found in 10 iterations.
    +
    +
    \ No newline at end of file diff --git a/html/b1080.html b/html/b1080.html new file mode 100644 index 0000000..18979a2 --- /dev/null +++ b/html/b1080.html @@ -0,0 +1,60 @@ + + +

    1080. MOOC期终成绩 (25)

    +
    +

    +对于在中国大学MOOC(http://www.icourse163.org/)学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满分100)。总评成绩的计算公式为 G = (G期中x 40% + G期末x 60%),如果 G期中 > G期末;否则总评 G 就是 G期末。这里 G期中 和 G期末 分别为学生的期中和期末成绩。 +

    +

    +现在的问题是,每次考试都产生一张独立的成绩单。本题就请你编写程序,把不同的成绩单合为一张。 +

    +

    +输入格式: +

    +

    +输入在第一行给出3个整数,分别是 P(做了在线编程作业的学生数)、M(参加了期中考试的学生数)、N(参加了期末考试的学生数)。每个数都不超过10000。 +

    +

    +接下来有三块输入。第一块包含 P 个在线编程成绩 G编程;第二块包含 M 个期中考试成绩 G期中;第三块包含 N 个期末考试成绩 G期末。每个成绩占一行,格式为:学生学号 分数。其中学生学号为不超过20个字符的英文字母和数字;分数是非负整数(编程总分最高为900分,期中和期末的最高分为100分)。 +

    +

    +输出格式: +

    +

    +打印出获得合格证书的学生名单。每个学生占一行,格式为: +

    +

    +学生学号 G编程 G期中 G期末 G +

    +

    +如果有的成绩不存在(例如某人没参加期中考试),则在相应的位置输出“-1”。输出顺序为按照总评分数(四舍五入精确到整数)递减。若有并列,则按学号递增。题目保证学号没有重复,且至少存在1个合格的学生。 +

    +输入样例:
    +6 6 7
    +01234 880
    +a1903 199
    +ydjh2 200
    +wehu8 300
    +dx86w 220
    +missing 400
    +ydhfu77 99
    +wehu8 55
    +ydjh2 98
    +dx86w 88
    +a1903 86
    +01234 39
    +ydhfu77 88
    +a1903 66
    +01234 58
    +wehu8 84
    +ydjh2 82
    +missing 99
    +dx86w 81
    +
    +输出样例:
    +missing 400 -1 99 99
    +ydjh2 200 98 82 88
    +dx86w 220 88 81 84
    +wehu8 300 55 84 84
    +
    +
    \ No newline at end of file diff --git a/html/b1081.html b/html/b1081.html new file mode 100644 index 0000000..30f0bac --- /dev/null +++ b/html/b1081.html @@ -0,0 +1,41 @@ + + +

    1081. 检查密码 (15)

    +
    +

    本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点".",还必须既有字母也有数字。 +

    +

    +输入格式: +

    +

    +输入第一行给出一个正整数 N(<=100),随后 N 行,每行给出一个用户设置的密码,为不超过80个字符的非空字符串,以回车结束。 +

    +

    +输出格式: +

    +

    +对每个用户的密码,在一行中输出系统反馈信息,分以下5种: +

    + +输入样例:
    +5
    +123s
    +zheshi.wodepw
    +1234.5678
    +WanMei23333
    +pass*word.6
    +
    +输出样例:
    +Your password is tai duan le.
    +Your password needs shu zi.
    +Your password needs zi mu.
    +Your password is wan mei.
    +Your password is tai luan le.
    +
    +
    \ No newline at end of file diff --git a/html/b1082.html b/html/b1082.html new file mode 100644 index 0000000..02fee7f --- /dev/null +++ b/html/b1082.html @@ -0,0 +1,32 @@ + + +

    1082. 射击比赛 (20)

    +
    +

    本题目给出的射击比赛的规则非常简单,谁打的弹洞距离靶心最近,谁就是冠军;谁差得最远,谁就是菜鸟。本题给出一系列弹洞的平面坐标(x,y),请你编写程序找出冠军和菜鸟。我们假设靶心在原点(0,0)。 +

    +

    +输入格式: +

    +

    +输入在第一行中给出一个正整数 N(<= 10 000)。随后 N 行,每行按下列格式给出:

    +
    +ID x y
    +
    +

    其中 ID 是运动员的编号(由4位数字组成);x 和 y 是其打出的弹洞的平面坐标(x,y),均为整数,且 0 <= |x|, |y| <= 100。题目保证每个运动员的编号不重复,且每人只打 1 枪。 +

    +

    +输出格式: +

    +

    +输出冠军和菜鸟的编号,中间空 1 格。题目保证他们是唯一的。 +

    +输入样例:
    +3
    +0001 5 7
    +1020 -1 3
    +0233 0 -1
    +
    +输出样例:
    +0233 0001
    +
    +
    \ No newline at end of file diff --git a/html/b1083.html b/html/b1083.html new file mode 100644 index 0000000..9bb5b04 --- /dev/null +++ b/html/b1083.html @@ -0,0 +1,28 @@ + + +

    1083. 是否存在相等的差 (20)

    +
    +

    给定 N 张卡片,正面分别写上 1、2、……、N,然后全部翻面,洗牌,在背面分别写上 1、2、……、N。将每张牌的正反两面数字相减(大减小),得到 N 个非负差值,其中是否存在相等的差? +

    +

    +输入格式: +

    +

    +输入第一行给出一个正整数 N(2 <= N <= 10000),随后一行给出 1 到 N 的一个洗牌后的排列,第 i 个数表示正面写了 i 的那张卡片背面的数字。 +

    +

    +输出格式: +

    +

    +按照“差值 重复次数”的格式从大到小输出重复的差值及其重复的次数,每行输出一个结果。 +

    +输入样例:
    +8
    +3 5 8 6 2 1 4 7
    +
    +输出样例:
    +5 2
    +3 3
    +2 2
    +
    +
    \ No newline at end of file diff --git a/html/b1084.html b/html/b1084.html new file mode 100644 index 0000000..3feb65c --- /dev/null +++ b/html/b1084.html @@ -0,0 +1,28 @@ + + +

    1084. 外观数列 (20)

    +
    +

    外观数列是指具有以下特点的整数序列:

    +d, d1, d111, d113, d11231, d112213111, ...
    +

    +它从不等于 1 的数字 d 开始,序列的第 n+1 项是对第 n 项的描述。比如第 2 项表示第 1 项有 1 个 d,所以就是 d1;第 2 项是 1 个 d(对应 d1)和 1 个 1(对应 11),所以第 3 项就是 d111。又比如第 4 项是 d113,其描述就是 1 个 d,2 个 1,1 个 3,所以下一项就是 d11231。当然这个定义对 d = 1 也成立。本题要求你推算任意给定数字 d 的外观数列的第 N 项。 +

    +

    +输入格式: +

    +

    +输入第一行给出[0,9]范围内的一个整数 d、以及一个正整数 N(<=40),用空格分隔。 +

    +

    +输出格式: +

    +

    +在一行中给出数字 d 的外观数列的第 N 项。 +

    +输入样例:
    +1 8
    +
    +输出样例:
    +1123123111
    +
    +
    \ No newline at end of file diff --git a/html/b1085.html b/html/b1085.html new file mode 100644 index 0000000..3df84bf --- /dev/null +++ b/html/b1085.html @@ -0,0 +1,55 @@ + + +

    1085. PAT单位排行 (25)

    +
    +

    每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜。本题就请你实现这个功能。 +

    +

    +输入格式: +

    +

    +输入第一行给出一个正整数N(<=105),即考生人数。随后N行,每行按下列格式给出一个考生的信息: +

    +

    +准考证号 得分 学校 +

    +

    +其中“准考证号”是由6个字符组成的字符串,其首字母表示考试的级别:“B”代表乙级,“A”代表甲级,“T”代表顶级;“得分”是 [0,100] 区间内的整数;“学校”是由不超过6个英文字母组成的单位码(大小写无关)。注意:题目保证每个考生的准考证号是不同的。 +

    +

    +输出格式: +

    +

    +首先在一行中输出单位个数。随后按以下格式非降序输出单位的排行榜: +

    +

    +排名 学校 加权总分 考生人数 +

    +

    +其中“排名”是该单位的排名(从1开始);“学校”是全部按小写字母输出的单位码;“加权总分”定义为“乙级总分/1.5 + 甲级总分 + 顶级总分*1.5”的整数部分;“考生人数”是该属于单位的考生的总人数。 +

    +

    +学校首先按加权总分排行。如有并列,则应对应相同的排名,并按考生人数升序输出。如果仍然并列,则按单位码的字典序输出。 +

    +输入样例:
    +10
    +A57908 85 Au
    +B57908 54 LanX
    +A37487 60 au
    +T28374 67 CMU
    +T32486 24 hypu
    +A66734 92 cmu
    +B76378 71 AU
    +A47780 45 lanx
    +A72809 100 pku
    +A03274 45 hypu
    +
    +输出样例:
    +5
    +1 cmu 192 2
    +1 au 192 3
    +3 pku 100 1
    +4 hypu 81 2
    +4 lanx 81 2
    +
    +
    \ No newline at end of file diff --git a/html/t1001.html b/html/t1001.html new file mode 100644 index 0000000..7ac1c2b --- /dev/null +++ b/html/t1001.html @@ -0,0 +1,15 @@ + + +

    1001. Battle Over Cities - Hard Version (35)

    +
    +

    It is vitally important to have all the cities connected by highways in a war. If a city is conquered by the enemy, all the highways from/toward that city will be closed. To keep the rest of the cities connected, we must repair some highways with the minimum cost. On the other hand, if losing a city will cost us too much to rebuild the connection, we must pay more attention to that city.

    +

    Given the map of cities which have all the destroyed and remaining highways marked, you are supposed to point out the city to which we must pay the most attention. +

    +

    Input Specification:

    +

    Each input file contains one test case. Each case starts with a line containing 2 numbers N (<=500), and M, which are the total number of cities, and the number of highways, respectively. Then M lines follow, each describes a highway by 4 integers:

    +
    +City1 City2 Cost Status
    +
    +

    where City1 and City2 are the numbers of the cities the highway connects (the cities are numbered from 1 to N), Cost is the effort taken to repair that highway if necessary, and Status is either 0, meaning that highway is destroyed, or 1, meaning that highway is in use.

    +

    Note: It is guaranteed that the whole country was connected before the war.

    +
    \ No newline at end of file diff --git a/html/t1002.html b/html/t1002.html new file mode 100644 index 0000000..f192982 --- /dev/null +++ b/html/t1002.html @@ -0,0 +1,31 @@ + + +

    1002. Business (35)

    +
    +

    As the manager of your company, you have to carefully consider, for each project, the time taken to finish it, the deadline, and the profit you can gain, in order to decide if your group should take this project. For example, given 3 projects as the following:

    +
  • Project[1] takes 3 days, it must be finished in 3 days in order to gain 6 units of profit. +
  • Project[2] takes 2 days, it must be finished in 2 days in order to gain 3 units of profit. +
  • Project[3] takes 1 day only, it must be finished in 3 days in order to gain 4 units of profit. +

    +You may take Project[1] to gain 6 units of profit. But if you take Project[2] first, then you will have 1 day left to complete Project[3] just in time, and hence gain 7 units of profit in total. Notice that once you decide to work on a project, you have to do it from beginning to the end without any interruption. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N(<=50), and then followed by N lines of projects, each contains three numbers P, L, and D where P is the profit, L the lasting days of the project, and D the deadline. It is guaranteed that L is never more than D, and all the numbers are non-negative integers.

    +

    +Output Specification: +

    +

    For each test case, output in a line the maximum profit you can gain. +

    +Sample Input:
    +4
    +7 1 3
    +10 2 3
    +6 1 2
    +5 1 1
    +
    +Sample Output:
    +18
    +
    +
  • \ No newline at end of file diff --git a/html/t1003.html b/html/t1003.html new file mode 100644 index 0000000..5a4b417 --- /dev/null +++ b/html/t1003.html @@ -0,0 +1,36 @@ + + +

    1003. Universal Travel Sites (35)

    +
    +

    After finishing her tour around the Earth, CYLL is now planning a universal travel sites development project. After a careful investigation, she has a list of capacities of all the satellite transportation stations in hand. To estimate a budget, she must know the minimum capacity that a planet station must have to guarantee that every space vessel can dock and download its passengers on arrival.

    +

    Input Specification:

    +

    Each input file contains one test case. For each case, the first line contains the names of the source and the destination planets, and a positive integer N (<=500). Then N lines follow, each in the format:

    +

    +sourcei destinationi capacityi +

    +

    +where sourcei and destinationi are the names of the satellites and the two involved planets, and capacityi > 0 is the maximum number of passengers that can be transported at one pass from sourcei to destinationi. Each name is a string of 3 uppercase characters chosen from {A-Z}, e.g., ZJU.

    +

    +Note that the satellite transportation stations have no accommodation facilities for the passengers. Therefore none of the passengers can stay. Such a station will not allow arrivals of space vessels that contain more than its own capacity. It is guaranteed that the list contains neither the routes to the source planet nor that from the destination planet. +

    +

    Output Specification:

    +

    For each test case, just print in one line the minimum capacity that a planet station must have to guarantee that every space vessel can dock and download its passengers on arrival. +

    +Sample Input:
    +EAR MAR 11
    +EAR AAA 300
    +EAR BBB 400
    +AAA BBB 100
    +AAA CCC 400
    +AAA MAR 300
    +BBB DDD 400
    +AAA DDD 400
    +DDD AAA 100
    +CCC MAR 400
    +DDD CCC 200
    +DDD MAR 300
    +
    +Sample Output:
    +700
    +
    +
    \ No newline at end of file diff --git a/html/t1004.html b/html/t1004.html new file mode 100644 index 0000000..8e11a48 --- /dev/null +++ b/html/t1004.html @@ -0,0 +1,40 @@ + + +

    1004. To Buy or Not to Buy - Hard Version (35)

    +
    +

    Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in whole pieces. Hence in some cases Eva might have to buy several strings to get all the beads she needs. With a hundred strings in the shop, Eva needs your help to tell her whether or not she can get all the beads she needs with the least number of extra beads she has to pay for.

    +

    For the sake of simplicity, let's use the characters in the ranges [0-9], [a-z], and [A-Z] to represent the colors. In sample 1, buying the 2nd and the last two strings is the best way since there are only 3 extra beads. In sample 2, buying all the three strings won't help since there are three "R" beads missing.

    +

    +Input Specification: +

    +

    Each input file contains one test case. Each case first gives in a line the string that Eva wants. Then a positive integer N (<=100) is given in the next line, followed by N lines of strings that belong to the shop. All the strings contain no more than 1000 beads.

    +

    +Output Specification: +

    +

    For each test case, print your answer in one line. If the answer is "Yes", then also output the least number of extra beads Eva has to buy; or if the answer is "No", then also output the number of beads missing from all the strings. There must be exactly 1 space between the answer and the number.

    +Sample Input 1:
    +RYg5
    +8
    +gY5Ybf
    +8R5
    +12346789
    +gRg8h
    +5Y37
    +pRgYgbR52
    +8Y
    +8g
    +
    +Sample Output 1:
    +Yes 3
    +
    +Sample Input 2:
    +YrRR8RRrY
    +3
    +ppRGrrYB225
    +8ppGrrB25
    +Zd6KrY
    +
    +Sample Output 1:
    +No 3
    +
    +
    \ No newline at end of file diff --git a/html/t1005.html b/html/t1005.html new file mode 100644 index 0000000..4c1eaa8 --- /dev/null +++ b/html/t1005.html @@ -0,0 +1,38 @@ + + +

    1005. Programming Pattern (35)

    +
    +

    +Programmers often have a preference among program constructs. For example, some may prefer "if(0==a)", while others may prefer "if(!a)". Analyzing such patterns can help to narrow down a programmer's identity, which is useful for detecting plagiarism. +

    +

    Now given some text sampled from someone's program, can you find the person's most commonly used pattern of a specific length? +

    +

    +Input Specification: +

    +

    +Each input file contains one test case. For each case, there is one line consisting of the pattern length N (1<=N<=1048576), followed by one line no less than N and no more than 1048576 characters in length, terminated by a carriage return '\n'. The entire input is case sensitive. +

    +

    +Output Specification: +

    +

    For each test case, print in one line the length-N substring that occurs most frequently in the input, followed by a space and the number of times it has occurred in the input. If there are multiple such substrings, print the lexicographically smallest one. +

    +

    +Whitespace characters in the input should be printed as they are. Also note that there may be multiple occurrences of the same substring overlapping each other. +

    +Sample Input 1:
    +4
    +//A can can can a can.
    +
    +Sample Output 1:
    + can 4
    +
    +Sample Input 2:
    +3
    +int a=~~~~~~~~~~~~~~~~~~~~~0;
    +
    +Sample Output 2:
    +~~~ 19
    +
    +
    \ No newline at end of file diff --git a/html/t1006.html b/html/t1006.html new file mode 100644 index 0000000..23f33e2 --- /dev/null +++ b/html/t1006.html @@ -0,0 +1,36 @@ + + +

    1006. Tree Traversals - Hard Version (35)

    +
    +

    Given the partial results of a binary tree's traversals in in-order, pre-order, and post-order. You are supposed to output the complete results and the level order traversal sequence of the corresponding tree.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, a positive integer N (<=100) is given in the first line. Then three lines follow, containing the incomplete in-order, pre-order and post-order traversal sequences, respectively. It is assumed that the tree nodes are numbered from 1 to N and no number is given out of the range. A "-" represents a missing number.

    +

    +Output Specification: +

    +

    For each case, print in four lines the complete in-order, pre-order and post-order traversal sequences, together with the level order traversal sequence of the corresponding tree. The numbers must be separated by a space, and there must be no extra space at the end of each line. If it is impossible to reconstruct the unique tree from the given information, simply print "Impossible". +

    +Sample Input 1:
    +9
    +3 - 2 1 7 9 - 4 6
    +9 - 5 3 2 1 - 6 4
    +3 1 - - 7 - 6 8 -
    +
    +Sample Output 1:
    +3 5 2 1 7 9 8 4 6
    +9 7 5 3 2 1 8 6 4
    +3 1 2 5 7 4 6 8 9
    +9 7 8 5 6 3 2 4 1
    +
    +Sample Input 2:
    +3
    +- - -
    +- 1 -
    +1 - -
    +
    +Sample Output 2:
    +Impossible
    +
    +
    \ No newline at end of file diff --git a/html/t1007.html b/html/t1007.html new file mode 100644 index 0000000..51091b0 --- /dev/null +++ b/html/t1007.html @@ -0,0 +1,29 @@ + + +

    1007. Red-black Tree (35)

    +
    +

    There is a kind of binary tree named red-black tree in the data structure. It has the following 5 properties:

    +

    +(1) Every node is either red or black.
    +(2) The root is black.
    +(3) All the leaves are NULL nodes and are colored black.
    +(4) Each red node must have 2 black descends (may be NULL).
    +(5) All simple paths from any node x to a descendant leaf have the same number of black nodes.

    +

    +We call a non-NULL node an internal node. From property (5) we can define the black-height of a red-black tree as the number of nodes on the simple path from the root (excluding the root itself) to any NULL leaf (including the NULL leaf). And we can derive that a red-black tree with black height H has at least 2H-1 internal nodes.

    +

    Here comes the question: given a positive N, how many distinct red-black trees are there that consist of exactly N internal nodes?

    +

    +Input Specification: +

    +

    Each input file contains one test case which gives a positive integer N (<= 500).

    +

    +Output Specification: +

    +

    For each case, print in a line the number of distinct red-black tees with N internal nodes. Since the answer may be very large, output the remainder of it divided by 1000000007 please.

    +Sample Input:
    +5
    +
    +Sample Output:
    +8
    +
    +
    \ No newline at end of file diff --git a/html/t1008.html b/html/t1008.html new file mode 100644 index 0000000..a363634 --- /dev/null +++ b/html/t1008.html @@ -0,0 +1,80 @@ + + +

    1008. Airline Routes (35)

    +
    +

    Given a map of airline routes, you are supposed to check if a round trip can be planned between any pair of cities.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives two positive integers N (2<= N <= 104) and M (<=6N), which are the total number of cities (hence the cities are numbered from 1 to N) and the number of airline routes, respectively. Then M lines follow, each gives the information of a route in the format of the source city index first, and then the destination city index, separated by a space. It is guaranteed that the source is never the same as the destination.

    +

    After the map information, another positive integer K is given, which is the number of queries. Then K lines of queries follow, each contains a pair of distinct cities' indices.

    +

    +Output Specification: +

    +

    For each query, output in a line "Yes" if a round trip is possible, or "No" if not.

    +Sample Input:
    +12 19
    +3 4
    +1 3
    +12 11
    +5 9
    +6 2
    +3 2
    +10 7
    +9 1
    +7 12
    +2 4
    +9 5
    +2 6
    +12 4
    +11 10
    +4 8
    +8 12
    +11 8
    +12 7
    +1 5
    +20
    +11 4
    +12 7
    +3 6
    +2 3
    +5 3
    +3 9
    +4 3
    +8 3
    +8 10
    +10 11
    +7 8
    +7 1
    +9 5
    +1 9
    +2 6
    +3 1
    +3 12
    +7 3
    +6 9
    +6 8
    +
    +Sample Output:
    +Yes
    +Yes
    +No
    +No
    +No
    +No
    +No
    +No
    +Yes
    +Yes
    +Yes
    +No
    +Yes
    +Yes
    +Yes
    +No
    +No
    +No
    +No
    +No
    +
    +
    \ No newline at end of file diff --git a/html/t1009.html b/html/t1009.html new file mode 100644 index 0000000..baa5926 --- /dev/null +++ b/html/t1009.html @@ -0,0 +1,22 @@ + + +

    1009. Triple Inversions (35)

    +
    +

    Given a list of N integers A1, A2, A3,...AN, there's a famous problem to count the number of inversions in it. An inversion is defined as a pair of indices i < j such that Ai > Aj.

    +

    Now we have a new challenging problem. You are supposed to count the number of triple inversions in it. As you may guess, a triple inversion is defined as a triple of indices i < j < k such that Ai > Aj > Ak. For example, in the list {5, 1, 4, 3, 2} there are 4 triple inversions, namely (5,4,3), (5,4,2), (5,3,2) and (4,3,2). To simplify the problem, the list A is given as a permutation of integers from 1 to N.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N in [3, 105]. The second line contains a permutation of integers from 1 to N and each of the integer is separated by a single space.

    +

    +Output Specification: +

    +

    For each case, print in a line the number of triple inversions in the list.

    +Sample Input:
    +22
    +1 2 3 4 5 16 6 7 8 9 10 19 11 12 14 15 17 18 21 22 20 13
    +
    +Sample Output:
    +8
    +
    +
    \ No newline at end of file diff --git a/html/t1010.html b/html/t1010.html new file mode 100644 index 0000000..0514a59 --- /dev/null +++ b/html/t1010.html @@ -0,0 +1,22 @@ + + +

    1010. Lehmer Code (35)

    +
    +

    According to Wikipedia: "In mathematics and in particular in combinatorics, the Lehmer code is a particular way to encode each possible permutation of a sequence of n numbers." To be more specific, for a given permutation of items {A1, A2, ..., An}, Lehmer code is a sequence of numbers {L1, L2, ..., Ln} such that Li is the total number of items from Ai to An which are less than Ai. For example, given {24, 35, 12, 1, 56, 23}, the second Lehmer code L2 is 3 since from 35 to 23 there are three items, {12, 1, 23}, less than the second item, 35.

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N (<= 105). Then N distinct numbers are given in the next line.

    +

    +Output Specification: +

    +

    For each test case, output in a line the corresponding Lehmer code. The numbers must be separated by exactly one space, and there must be no extra space at the beginning or the end of the line. +

    +Sample Input:
    +6
    +24 35 12 1 56 23
    +
    +Sample Output:
    +3 3 1 0 1 0
    +
    +
    \ No newline at end of file diff --git a/html/t1011.html b/html/t1011.html new file mode 100644 index 0000000..c58ecb2 --- /dev/null +++ b/html/t1011.html @@ -0,0 +1,57 @@ + + +

    1011. Cut Rectangles (35)

    +
    +

    When a rectangle is cut by a straight line, we can easily obtain two polygons as the result. But the reversed problem is harder: given two polygons, your task is to check whether or not they could be obtained by cutting a rectangle.

    +

    To give you more trouble, the input polygons are possibly moved, rotated (90 degrees, 180 degrees, or 270 degrees counter-clockwise), or even flipped (mirrored).

    +

    +It is assumed that the original rectangle's edges are parallel to the axis. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N(<=20), and then N pairs of polygons are given. Each polygon is described in the format:

    +

    +k x1 y1 ... xk yk +

    +

    +where k (2 < k <= 10) is the number of vertices on the polygon, and (xi, yi) (0 <= xi, yi <= 108) are the coordinates of the vertices, given in either clockwise or counter-clockwise order. +

    +

    +Note: there is no redundant vertex. That is, it is guaranteed that all the vertices are distinct for each polygon, and that no three consecutive vertices are on the same line. +

    +

    +Output Specification: +

    +

    For each pair of polygons, print in a line either "YES" or "NO" as the answer. +

    +Sample Input:
    +8
    +3 0 0 1 0 1 1
    +3 0 0 1 1 0 1
    +3 0 0 1 0 1 1
    +3 0 0 1 1 0 2
    +4 0 4 1 4 1 0 0 0
    +4 4 0 4 1 0 1 0 0
    +3 0 0 1 1 0 1
    +4 2 3 1 4 1 7 2 7
    +5 10 10 10 12 12 12 14 11 14 10
    +3 28 35 29 35 29 37
    +3 7 9 8 11 8 9
    +5 87 26 92 26 92 23 90 22 87 22
    +5 0 0 2 0 1 1 1 2 0 2
    +4 0 0 1 1 2 1 2 0
    +4 0 0 0 1 1 1 2 0
    +4 0 0 0 1 1 1 2 0
    +
    +Sample Output:
    +YES
    +NO
    +YES
    +YES
    +YES
    +YES
    +NO
    +YES
    +
    +
    \ No newline at end of file diff --git a/html/t1012.html b/html/t1012.html new file mode 100644 index 0000000..1487c22 --- /dev/null +++ b/html/t1012.html @@ -0,0 +1,77 @@ + + +

    1012. Greedy Snake (35)

    +
    +

    Have you ever played the game "Greedy Snake"? In the game, we control the movements of the snake to eat the fruits scattered in the game field, while the snake's body gets longer whenever it eats a fruit. The goal of the game is to make the snake eat as many fruits as possible, before its head has no where to go. It would be a real challenge to let you program this game, right now.

    +
    +

    But hey! Relax! This time you are only asked to program a simplified version of the game. In this simple version, the fruits are all over the place except at some extra obstacle cells. The snake's body will extend all the way along the path while it eats the fruits. You may take any fruit cell as the starting position of the snake. Then you have four directions to choose from: UP, DOWN, LEFT or RIGHT. Once you pick up a direction for the snake, it must keep going until it hits an obstacle or its own body. This procedure repeats until the head of the snake has no where to go -- that is, every adjacent cell of its head is either an obstacle or its own body. Your task is to minimize the number of fruits left.

    +

    For example, let's define the game field to be a 6 by 6 maze, surrounded by obstacle cells "#", with one extra obstacle "@". "S" is the starting position of the snake. All the fruits are represented by dots.

    +
    +######
    +#..S@#
    +#....#
    +#....#
    +#....#
    +######
    +
    +

    +Then if you decide to move DOWN, RIGHT, and UP, the results are shown below. +

    +
    +######
    +#..*@#
    +#..*.#
    +#..*.#
    +#..S.#
    +######
    +
    +######
    +#..*@#
    +#..*.#
    +#..*.#
    +#..*S#
    +######
    +
    +######
    +#..*@#
    +#..*S#
    +#..**#
    +#..**#
    +######
    +
    +

    +Now the snake is stucked, the game is over, and there are 8 fruits left. However, by carefully changing your moves or choosing another starting position, you can actually control the snake to eat up all the fruits. Try it out! +

    +

    +Task 1: minimize the number of fruits left, and count the number of starting positions that can lead to the optimal solution. +

    +

    +Task 2: To make things more interesting, you may replace one fruit cell by an obstacle, to obtain a better result, and count the number of ways to add an obstacle that leads to the better result. In case there is no way to improve the result by adding one obstacle, you should point out this situation. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains two integers N (4 <= N <= 15), the size of the game field, and K (0 <= K <= 2), the number of extra obstacles. Then K lines follow, each gives the coordinates of an obstacle in the format "xi yi" where 2 <= xi, yi <= N-1.

    +

    +Output Specification: +

    +

    For each case, print the results in two lines. In the first line print the minimal number of fruits left, and the number of different optimal starting positions. Then in the second line, either print -1 if there is no way to improve the result, or two integers: the better result and the number of optimal ways to add an obstacle. +

    +Sample Input 1:
    +6 1
    +2 5
    +
    +Sample Output 1:
    +0 4
    +-1
    +
    +Sample Input 2:
    +6 2
    +2 2
    +3 3
    +
    +Sample Output 2:
    +2 1
    +0 2
    +
    +
    \ No newline at end of file diff --git a/html/t1013.html b/html/t1013.html new file mode 100644 index 0000000..e031d9e --- /dev/null +++ b/html/t1013.html @@ -0,0 +1,14 @@ + + +

    1013. Image Segmentation (35)

    +
    +

    Image segmentation is usually formulated as a graph partition problem, where each segment corresponds to a connected component. Moreover, each pixel is the vertex of the graph. Each edge has a weight, which is a non-negative dissimilarity between neighboring pixels. So, the goal of image segmentation is to decompose the image graph into several disconnected components, where the elements in a component are similar and the elements in the different components are dissimilar.

    +

    The components are defined as follows:

    +
    \ No newline at end of file diff --git a/html/t1014.html b/html/t1014.html new file mode 100644 index 0000000..494d536 --- /dev/null +++ b/html/t1014.html @@ -0,0 +1,51 @@ + + +

    1014. Circles of Friends (35)

    +
    +

    A circle of friends is a network of friend relationships. If A is a friend of B, then B is considered a friend of A no matter B admits or not, and they are said to belong to the same circle. Here we assume that friendship is transitive, that is, if A is a friend of B, and B is a friend of C, then A is a friend of C and the three of them all belong to the same circle. +

    +

    +On the other hand, A is not so close to C as B is. We define the distance D(X, Y) between two friends X and Y as the minimum number of friends between them. For example, D(A, B) = 0, and D(C, A) = 1. The diameter of a friends circle is the maximum distance between any pair of friends in the circle. +

    +

    +Now given some people's relationships, you are supposed to find the number of friends circles and the circle with the largest diameter. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives an integer N (2 <= N <= 1000), which is the total number of people involved, and hence they are numbered from 1 to N. Then N lines follow, each in the format:

    +

    +k p1 ... pk +

    +

    +where k (0 <= k < min(10, N)) is the number of friends and p1 to pk (if k>0) are the friends' indices. The i-th line corresponds to the i-th person. All the numbers in a line are separated by spaces. It is guaranteed that no one is given as a friend of oneself. +

    +

    +Output Specification: +

    +

    For each case, print in a line the number of friends circles, and the largest diameter, separated by exactly one space. +

    +Sample Input:
    +17
    +2 15 12
    +1 17
    +2 16 9
    +1 8
    +4 10 13 15 14
    +0
    +2 11 14
    +1 4
    +2 2 3
    +2 13 11
    +2 15 7
    +2 1 14
    +2 5 15
    +0
    +0
    +1 3
    +1 2
    +
    +Sample Output:
    +4 3
    +
    +
    \ No newline at end of file diff --git a/html/t1015.html b/html/t1015.html new file mode 100644 index 0000000..da574d3 --- /dev/null +++ b/html/t1015.html @@ -0,0 +1,34 @@ + + +

    1015. Letter-moving Game (35)

    +
    +

    Here is a simple intersting letter-moving game. The game starts with 2 strings S and T consist of lower case English letters. S and T contain the same letters but the orders might be different. In other words S can be obtained by shuffling letters in String T. At each step, you can move one arbitrary letter in S either to the beginning or to the end of it. How many steps at least to change S into T? +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line contains the string S, and the second line contains the string T. They consist of only the lower case English letters and S can be obtained by shuffling T's letters. The length of S is no larger than 1000.

    +

    +Output Specification: +

    +

    For each case, print in a line the least number of steps to change S into T in the game. +

    +Sample Input:
    +iononmrogdg
    +goodmorning
    +
    +Sample Output:
    +8
    +
    +Sample Solution:
    +(0) starts from iononmrogdg
    +(1) Move the last g to the beginning: giononmrogd
    +(2) Move m to the end: giononrogdm
    +(3) Move the first o to the end: ginonrogdmo
    +(4) Move r to the end: ginonogdmor
    +(5) Move the first n to the end: gionogdmorn
    +(6) Move i to the end: gonogdmorni
    +(7) Move the first n to the end: googdmornin
    +(8) Move the second g to the end: goodmorning
    +
    +
    \ No newline at end of file diff --git a/html/t1016.html b/html/t1016.html new file mode 100644 index 0000000..6d40716 --- /dev/null +++ b/html/t1016.html @@ -0,0 +1,54 @@ + + +

    1016. Uniqueness of MST (35)

    +
    +

    Given any weighted undirected graph, there exists at least one minimum spanning tree (MST) if the graph is connected. Sometimes the MST may not be unique though. Here you are supposed to calculate the minimum total weight of the MST, and also tell if it is unique or not. +

    +

    Input Specification:

    +

    Each input file contains one test case. Each case starts with a line containing 2 numbers N (<= 500), and M, which are the total number of vertices, and the number of edges, respectively. Then M lines follow, each describes an edge by 3 integers:

    +

    +V1 V2 Weight +

    +

    where V1 and V2 are the two ends of the edge (the vertices are numbered from 1 to N), and Weight is the positive weight on that edge. It is guaranteed that the total weight of the graph will not exceed 230.

    +

    Output Specification:

    +

    For each test case, first print in a line the total weight of the minimum spanning tree if there exists one, or else print "No MST" instead. Then if the MST exists, print in the next line "Yes" if the tree is unique, or "No" otherwise. If there is no MST, print the number of connected components instead. +

    +Sample Input 1:
    +5 7
    +1 2 6
    +5 1 1
    +2 3 4
    +3 4 3
    +4 1 7
    +2 4 2
    +4 5 5
    +
    +Sample Output 1:
    +11
    +Yes
    +
    +Sample Input 2:
    +4 5
    +1 2 1
    +2 3 1
    +3 4 2
    +4 1 2
    +3 1 3
    +
    +Sample Output 2:
    +4
    +No
    +
    +Sample Input 3:
    +5 5
    +1 2 1
    +2 3 1
    +3 4 2
    +4 1 2
    +3 1 3
    +
    +Sample Output 3:
    +No MST
    +2
    +
    +
    \ No newline at end of file diff --git a/html/t1017.html b/html/t1017.html new file mode 100644 index 0000000..f278455 --- /dev/null +++ b/html/t1017.html @@ -0,0 +1,34 @@ + + +

    1017. The Best Peak Shape (35)

    +
    +

    In many research areas, one important target of analyzing data is to find the best "peak shape" out of a huge amount of raw data full of noises. A "peak shape" of length L is an ordered sequence of L numbers { D1, ..., DL } satisfying that there exists an index i (1 < i < L) such that D1 < ... < Di-1 < Di > Di+1 > ... > DL. +

    +

    +Now given N input numbers ordered by their indices, you may remove some of them to keep the rest of the numbers in a peak shape. The best peak shape is the longest sub-sequence that forms a peak shape. If there is a tie, then the most symmetric (meaning that the difference of the lengths of the increasing and the decreasing sub-sequences is minimized) one will be chosen. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives an integer N (3 <= N <= 104). Then N integers are given in the next line, separated by spaces. All the integers are in [-10000, 10000]. +

    +

    +Output Specification: +

    +

    For each case, print in a line the length of the best peak shape, the index (starts from 1) and the value of the peak number. If the solution does not exist, simply print "No peak shape" in a line. The judge's input guarantees the uniqueness of the output. +

    +Sample Input 1:
    +20
    +1 3 0 8 5 -2 29 20 20 4 10 4 7 25 18 6 17 16 2 -1
    +
    +Sample Output 1:
    +10 14 25
    +
    +Sample Input 2:
    +5
    +-1 3 8 10 20
    +
    +Sample Output 2:
    +No peak shape
    +
    +
    \ No newline at end of file diff --git a/html/t1018.html b/html/t1018.html new file mode 100644 index 0000000..43c871b --- /dev/null +++ b/html/t1018.html @@ -0,0 +1,19 @@ + + +

    1018. Subnumbers (35)

    +
    +

    Given a positive integer N, let us define a "subnumber" of N as a consecutive number of digits NOT starting with 0. For example if N = 1021, it has 7 subnumbers, namely, 1, 10, 102, 1021, 2, 21 and 1 (again). Here is your task: please calculate the sum of all the subnumbers of N. For 1021, the sum is 1+10+102+1021+2+21+1 = 1158. Since the result may be very large, output the answer modulo 1000000007 (109 + 7) please.

    +

    +Input Specification: +

    +

    Each input file contains one test case, which gives the integer N (0 < N < 10100000) in a line.

    +

    +Output Specification: +

    +

    Print in a line the sum of all N's subnumbers (modulo 1000000007).

    +Sample Input:
    +1234567890123456789
    +Sample Output:
    +332876913
    +
    +
    \ No newline at end of file diff --git a/html/t1019.html b/html/t1019.html new file mode 100644 index 0000000..1342cd2 --- /dev/null +++ b/html/t1019.html @@ -0,0 +1,53 @@ + + +

    1019. Separate the Animals (35)

    +
    +

    There are some animals in a zoo which can be described as a grid with N rows and M columns. Your task is to place some obstacles so that no pairs of animals can reach each other. +

    +

    +Two animals can reach each other if and only if their cells are 4-connected. For example, in Figure 1, the central blue cell can be reached by the four red cells, and cannot be reached by the other four white cells. +

    +

    Figure 1
    +

    +What is more, you must put obstacles in exactly K cells, which are 4-connected and form exactly H holes. Here a hole is defined as a 4-connected part with finitely many open cells while the zoo is placed in an infinite open grid. For example, there are 2 holes (the green and the yellow areas) in Figure 2. +

    +

    Figure 2
    +

    +For the following grid with two animals: +

    +

    Figure 3
    +

    +If K = 8 and H = 1, one way to separate them is the following: +

    +

    Figure 4
    +

    +Figure 5 is illegal because it contains no hole. +

    +

    Figure 5
    +

    +Figure 6 is also illegal because the obstacles are not 4-connected. +

    +

    Figure 6
    +

    +Given some animals, you are supposed to count the number of different solutions. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives four integers: N, M, K, H (2 <= N, M <= 6; 1 <= K <= 12; 0 <= H <= 2). All the numbers are separated by spaces.

    +

    Then N lines follow, each contains M characters, which are either "." or "O", representing an open cell or an animal, respectively. There will be at least 2 animals. +

    +

    +Output Specification: +

    +

    For each case, print a single line containing a single integer: the number of solutions.

    +Sample Input:
    +3 5 8 1
    +...O.
    +.O...
    +.....
    +
    +Sample Output:
    +8
    +
    +
    \ No newline at end of file diff --git a/html/t1020.html b/html/t1020.html new file mode 100644 index 0000000..3c0cbb3 --- /dev/null +++ b/html/t1020.html @@ -0,0 +1,30 @@ + + +

    1020. Delete At Most Two Characters (35)

    +
    +

    Given a string which contains only lower case English letters, how many different strings you can get after deleting AT MOST TWO characters in it? +

    +

    +Input Specification: +

    +

    Each input file contains one test case, which gives the string whose length is in [3, 106]. +

    +

    +Output Specification: +

    +

    Print in a line the number of different strings you can get after deleting at most 2 characters. +

    +Sample Input:
    +ababcc
    +
    +Sample Output:
    +15
    +
    +

    +Hint:

    +

    +Deleting 0 character gets "ababcc".
    +Deleting 1 character gets "babcc", "aabcc", "abbcc", "abacc" and "ababc".
    +Deleting 2 character gets "abcc", "bbcc", "bacc", "babc", "aacc", "aabc", "abbc", "abac" and "abab".
    +

    +
    \ No newline at end of file diff --git a/html/t1021.html b/html/t1021.html new file mode 100644 index 0000000..d910473 --- /dev/null +++ b/html/t1021.html @@ -0,0 +1,62 @@ + + +

    1021. Safe Fruit (35)

    +
    +

    There are a lot of tips telling us that some fruits must not be eaten with some other fruits, or we might get ourselves in serious trouble. For example, bananas can not be eaten with cantaloupe (哈密瓜), otherwise it will lead to kidney deficiency (肾虚).

    +

    +Now you are given a long list of such tips, and a big basket of fruits. You are supposed to pick up those fruits so that it is safe to eat any of them. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives two positive integers: N, the number of tips, and M, the number of fruits in the basket. both numbers are no more than 100.

    +

    Then two blocks follow. The first block contains N pairs of fruits which must not be eaten together, each pair occupies a line and there is no duplicated tips; and the second one contains M fruits together with their prices, again each pair in a line. To make it simple, each fruit is represented by a 3-digit ID number. A price is a positive integer which is no more than 1000. All the numbers in a line are separated by spaces.

    +

    +Output Specification: +

    +

    For each case, first print in a line the maximum number of safe fruits. Then in the next line list all the safe fruits, in increasing order of their ID's. The ID's must be separated by exactly one space, and there must be no extra space at the end of the line. Finally in the third line print the total price of the above fruits. Since there may be many different solutions, you are supposed to output the one with a maximum number of safe fruits. In case there is a tie, output the one with the lowest total price. It is guaranteed that such a solution is unique.

    +Sample Input:
    +16 20
    +001 002
    +003 004
    +004 005
    +005 006
    +006 007
    +007 008
    +008 003
    +009 010
    +009 011
    +009 012
    +009 013
    +010 014
    +011 015
    +012 016
    +012 017
    +013 018
    +020 99
    +019 99
    +018 4
    +017 2
    +016 3
    +015 6
    +014 5
    +013 1
    +012 1
    +011 1
    +010 1
    +009 10
    +008 1
    +007 2
    +006 5
    +005 3
    +004 4
    +003 6
    +002 1
    +001 2
    +
    +Sample Output:
    +12
    +002 004 006 008 009 014 015 016 017 018 019 020
    +239
    +
    +
    \ No newline at end of file diff --git a/html/t1022.html b/html/t1022.html new file mode 100644 index 0000000..46b9fd0 --- /dev/null +++ b/html/t1022.html @@ -0,0 +1,63 @@ + + +

    1022. Werewolf (35)

    +
    +

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game,

    + +

    +Given that there were 2 werewolves among them, at least one but not all the werewolves were lying, and there were exactly 2 liers. Can you point out the werewolves? +

    +

    +Now you are asked to solve a harder vertion of this problem: given that there were N players, with M werewolves among them, at least one but not all the werewolves were lying, and there were exactly L liers. You are supposed to point out the werewolves. +

    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives three positive integer N (5 <= N <= 100), M and L (2 <= M,L < N). Then N lines follow and the i-th line gives the statement of the i-th player (1 <= i <= N), which is represented by the index of the player with a positive sign for a human and a negative sign for a werewolf. +

    +

    +Output Specification: +

    +

    If a solution exists, print in a line in descending order the indices of the M werewolves. The numbers must be separated by exactly one space with no extra spaces at the beginning or the end of the line. If there are more than one solution, you must output the largest solution sequence -- that is, for two sequences A = { a[1], ..., a[M] } and B = { b[1], ..., b[M] }, if there exists 0 <= k < M such that a[i]=b[i] (i <= k) and a[k+1]>b[k+1], then A is said to be larger than B. In case there is no solution, simply print "No Solution".

    +Sample Input 1:
    +5 2 2
    +-2
    ++3
    +-4
    ++5
    ++4
    +
    +Sample Output 1:
    +4 1
    +
    +Sample Input 2:
    +6 2 3
    +-2
    ++3
    +-4
    ++5
    ++4
    +-3
    +
    +Sample Output 2 (the solution is not unique):
    +6 4
    +
    +Sample Input 3:
    +6 2 5
    +-2
    ++3
    +-4
    ++5
    ++4
    ++6
    +
    +Sample Output 3:
    +No Solution
    +
    +
    \ No newline at end of file diff --git a/html/t1023.html b/html/t1023.html new file mode 100644 index 0000000..240ca30 --- /dev/null +++ b/html/t1023.html @@ -0,0 +1,32 @@ + + +

    1023. The Best Polygon (35)

    +
    +

    An n-gon is a polygon with n sides. For example, a triangle is a 3-gon. Now you are asked to find the best n-gon in a given convex N-gon. The vertices of the n-gon are selected from vertices of the N-gon. The n-gon you are supposed to find must have the largest area among all possible n-gons, which means that it approximates the N-gon the best. The figure below shows the best 6-gon (the shaded part) in a 10-gon.

    +
    +

    +Input Specification: +

    +

    Each input file contains one test case. For each case, the first line gives a positive integer N ( 6 <= N <= 300 ) which is the total number of vertices of the convex N-gon, and n ( 6 <= n <= min(10, N) ) which is the total number of vertices of the approximating convex n-gon. Then N lines follow, the i-th line gives the 2-D coordinates (x, y) of the i-th vertex ( i = 0, ... , N-1 ). The x and y coordinates in a line are real numbers with their absolute values no more than 1000, and they are separated by a space.

    +

    +Output Specification: +

    +

    Print in a line all the vertex indices of the best n-gon in descending order. All the numbers are separated by a space and there must be no extra space at the beginning or the end of the line. It is guaranteed that the solution is unique. +

    +Sample Input:
    +10 6
    +133.0 1.0
    +544.0 71.0
    +558.0 206.0
    +536.0 338.0
    +463.0 436.0
    +330.0 503.0
    +188.0 499.0
    +305.0 2.0
    +55.0 410.0
    +2.0 140.0
    +
    +Sample Output:
    +9 8 5 3 1 0
    +
    +
    \ No newline at end of file