MicrosoftOA #23
Find Min Num Moves
估计中等可在线判题
Each operation flips one B/W cell. Make every row and every column read the same forwards and backwards, and find the minimum number of flips. The input uses uppercase B/W throughout.
输入格式
This site's ranges: the first line contains N M (1..500), followed by N lines each with M characters B/W.
输出格式
Output a single integer, the answer.
样例 1
输入:
1 2
BW
输出:
1
样例 2
输入:
2 2
BW
WB
输出:
2
样例 3
输入:
3 3
BWB
WWW
BWB
输出:
0
样例说明
Example 1: the two cells must match, so flip either one; the answer is 1.
Example 2: the four corners belong to the same group, with two B and two W, so at least 2 cells must be flipped.
Example 3: every row and column is already a palindrome, so the answer is 0.