HDU 5630 Rikka with Chess

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5630

题意:一个n*m的黑白相间的棋盘,每次可以选择一个矩形把其中的所有格子反色,把所有格子变成一种颜色时的最少的操作次数

思路:可以说是最水的一次BC了,刚几分钟就几百A了,我却搞了十几分钟,刚开始想的是一块一块换,后来才想到是一行一行换,如4.4,先换2.4行,再换1.3列等。n或m是奇数换偶数行偶数列,偶数就无所谓了

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>

const int inf = 0x7f7f7f7f;//2139062143
typedef long long ll;
using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        printf("%d\n",n/2+m/2);
    }
    return 0;
}


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