hdoj5630 Rikka with Chess

题目描述:

Problem Description
Yuta gives Rikka a chess board of size n×m
.As we all know, on a chess board, every cell is either black or white and every two cells that share a side have different colors.Rikka can choose any rectangle formed by board squares and perform an inversion, every white cell becomes black, and vice versa.Rikka wants to turn all cells into the same color, please tell Rikka the minimal number of inversions she need to achieve her goal.
Input
The first line contains a number T(T≤10)
——The number of the testcases.Each testcase contains two numbers n,m(n≤109,m≤109)
Output
For each testcase, print a single number which represents the answer.
Sample Input
3
1 2
2 2
3 3
Sample Output
1
2
2

此题是说有一个n*m的棋盘,棋盘黑白相间(相邻格子的颜色不相同),每次可以使一行或一列的格子的颜色翻转(黑变白,白变黑),问至少多少次可以使棋盘上的格子全为一种颜色。

此题可以通过画图找到规律。

参考代码:

#include 
using namespace std;
int min_chess(int &n,int &m) {
    int min;
    min = n / 2 + m / 2;
    return min;
}
int main() {
    int t;
    int n,m;
    cin >> t;
    while (t--) {
        cin >> n >> m;
        int min = min_chess(n,m);
        cout << min << endl;
    }
    return 0;
}

你可能感兴趣的:(hdoj5630 Rikka with Chess)