Programmer's written test programming questions collection (3)

1. Niuniu likes strings very much, but he prefers palindrome strings to strings. We define a string as a palindrome string, if and only if it is read from front to back and from back to front the same. Now Niuniu wants to know how many characters it needs to replace at least for any string to turn it into a palindrome string. In a replacement operation, Niuniu can select a character at any position and turn it into another character.
Input description:
An integer N in the first line represents the length of the palindrome string. The
next line of N lowercase letters represents the string
output description:
Output an integer to indicate the answer.
Example 1:
Input:
5
acacb
Output:
1

Example 2:
Input:
4
acac
Output:
2

2. FIG grid give you a NXM now you claim wherein each small box 1 X 1 were stained, the following:
the number of the lattice is the same for each color staining of
adjacent lattice dyed different colors
all The grid must be dyed.
Now ask how many colors are required to complete the task.
Input description:
A positive integer T in the first line represents the number of test data groups.
Next, the positive integers N and M separated by two spaces in each line of T, represent the number of rows and columns of the grid.
1<=T<=100
1<=N,M<= 1 0 8 10^8108
Output description:
A total of T lines and each line an integer represents the answer.
Example 1:
Input:
1
2 2
Output:
2

3. Niuniu gives you a number n, which is divided into the sum of k numbers, so that the partial sum of these k numbers can represent all the numbers from 1 to n. For example, when n=6 and k=3, divide 6 into 1, 2, 3, then 1=1,2=2,3=3,4=1+3,5=2+3,6=1+ 2+3, now give you n, what is the smallest k.
Input description: The
first line is a t, which means there are t groups of data.
Next there are t lines, each with an integer n
1<=t<=1000,1<=n<= 1 0 9 10^9109
Output description: The
output is t rows, each row represents a minimum k
Example 1:
Input:
2
6
2
Output:
3
2

4. Given a rectangle a of size n*m, perform exactly k operations. For each operation, you can select a row or a column, add all the values ​​of its elements to sum, and then subtract d from these numbers. Find the maximum value of sum.
Input description: the
first row of four numbers n, m, k, d, the
next n rows and m columns represent matrix a.
1<=n,m<= 1 0 3 10^3103,1<=k<= 1 0 5 10^5 105,0<=d<=100,1<= a i , j a_{i,j} ai,j<=1000
Output description:
One number on a line represents the answer
Example 1:
Input:
2 2 2 2
2 3
3 3
Output:
11

Guess you like

Origin blog.csdn.net/qq_34124009/article/details/107950319