- A
n*m/2. - B
Record the occurrences' number of each letters, signed as cnt[char].
For each char in string, get the cnt[c]^2 plus together, and this is the answer. - C
Calculate the Convex Hull.
The sum of the max value between x-difference and y-difference of each adjacent points in the convex hull's set and 4 is the answer.
4 step can make a circle of 360 degree. - D
Counting the answer with Half, and check the answer using Dynamic Programming.
Let dp[i][j] means the probability of first i objects where j of them exploded, and the transfering formular is:
dp[i][j] = P(i) * dp[i - 1][j - 1] + (1 - P(i)) * dp[i - 1][j], where P(i) means the i-th object exploding's probability.