| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10985 | Column Sum and Row Sum |
|
| 10986 | K Characters |
|
| 10987 | Parentheses Matching |
|
| 10988 | Stable Sort |
|
| 10989 | Mouse Maze |
|
Description
Given a M*N integer array, please output the smallest column-sum and row-sum.
Input
There are multiple test cases. Each case starts with two integers M and N in a line. Then a M*N integer array follows. Integers are separated by blank. All the numbers in the array are in the range [-107, 107]. Please see the sample input.
Case 1: 1 <= M, N <= 10
Case 2: 1 <= M, N <= 100
Case 3: 1 <= M, N <= 1000
Case 4: 1 <= M, N <= 100000, 1 <= M*N <= 1000000
Note : Don't use cin/cout for input/output.
Output
For each case, output the smallest column-sum and row-sum in a line, separated by a blank.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
S="ABCDEFG...XYZabcdefg...xyz"
Given two intergers M and N, output all different possible sets of N characters from the first M characters in S. Print the sets in ASCII order(i.e. 'A'<'B'<'C'...<'Z'<'a'<'b'...<'z'). Each set should only be printed once, and the elements in the set should also be sorted in ASCII order.
For example, given M=3, N=2, you should output C(3,2)=3 lines, representing different sets of 2 charcters from the set {A,B,C}(first 3 charaters in S). The correct output is:
AB
AC
BC
Note that set {A,B} = {B,A}, thus should only be output once.
Input
The first line of input contains a positive interger T(T<=30), which indicates the number of test case. For the next T lines, each line contains two positive integers M, N (M^N<10^7, M>=N).
case1: 1<=M<=10, 1<=N<=2
case2: 1<=M<=26, 1<=N<=10
case3: 1<=M<=52, 1<=N<=10
case4: 1<=M<=52, 1<=N<=20
Output
For each test case, output all different possible sets of N characters from the first M characters in S. Each set a line, sorted in ASCII order.
Print a blank line after each test case.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
A string is said to be valid if it matches one of the following rules:
(1) The string is an empty string.
(2) If a string S is valid, then {S}, [S], (S) and <S> are valid.
(3) If strings S1 and S2 are both valid, then S1S2 is valid.
Given a string consisting of parentheses, determine if it is a valid string.
Input
The first line of the input contains an integer N (N ≤ 10000) denoting the number of test cases followed by. Each of the next N lines corresponds to a test case, which contains a string consisting of parentheses, and the maximum string length will be no more than 1000. Note that an empty string (a line which contains the newline character only) may be contained in the input and it should be considered as a valid string according to rule (1).
Output
For each test case, print “Case i:” and then “Yes” or “No” to indicate that the string is valid or not, separated by a space character. i is the test case number starting from 1.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given the grades of N people. Please output the sorted result. (Increasing order)
Input
The input includes multiple test cases.
In each test case, the first line contains one integer N. The following N lines specify the name Si and the grade Gi.
1 <= |Si| <= 10 (Only contain a-z, A-Z)
0 <= Gi <= 100 (Gi is an integer.)
Test Case 1 : 1 <= N <= 102
Test Case 2 : 1 <= N <= 104
Test Case 3 : 1 <= N <= 105
Test Case 4 : 1 <= N <= 106
Output
For every test case, output the result in N lines. Every line contains the name and the grade. If more people’s grades are same, output by input order. (That means it uses stable sort. And also please use faster input/output.)
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Write a program that simulates a mouse in a maze. The program must count the steps taken by the mouse from the starting point to the final point.
The maze type is shown in following figure:
S$###
$$#$$
$$$##
##$$F
it consists of S (starting point), #(walls), $(road) and F (final point).
In above case, it needs 7 steps from S to F as following figure,
S$###
$$#$$
$$$##
##$$F
and the mouse can move in the four directions: up, down, left, right. There may be more than one way to reach final point, the program only need to print the least steps.
If there is no way from S to F, then print -1.
Input
The first line has an integer N(1<=N<=1000), which means the number of test cases.
For each case, the first line has two integers. The first and second integers R and C (3<=R, C<=500) represent the numbers of rows and columns of the maze, respectively. The total number of elements in the maze is thus R x C.
The following R lines, each containing C characters, specify the elements of the maze.
Output
Print out the least steps for each case, and there is a new line character at the end of each line.