hdu 5630 Rikka with Chess (暴力 ,计数问题)

http://acm.hdu.edu.cn/showproblem.php?pid=5630 题意:nm的棋盘,相邻格子的颜色相反,每次可以翻转一个任意大小矩形的格子,问最少需要翻转多少次使得棋盘的nm个格子颜色相同。(翻转的意思是颜色反色)

思路:手写了下。。发现。。答案就是n/2+m/2. 对应的最优策略是。。翻偶数行和偶数列,都翻一遍,颜色就一样了。

/* ***********************************************
Author :111qqz
Created Time :2016年03月03日 星期四 20时47分47秒
File Name :code/hdu/5630.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
 1using namespace std;
 2const double eps = 1E-8;
 3const int dx4[4]={1,0,0,-1};
 4const int dy4[4]={0,-1,1,0};
 5const int inf = 0x3f3f3f3f;
 6int n,m;
 7int main()
 8{
 9	#ifndef  ONLINE_JUDGE 
10	freopen("code/in.txt","r",stdin);
11  #endif
1	ios::sync_with_stdio(false);
2	int T;
3	cin>>T;
4	while (T--)
5	{
6	    cin>>n>>m;
7	    cout<<n/2+m/2<<endl;
8	}
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}