Rikka with Chess
Accepts: 393
Submissions: 548
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
一个n×m的黑白相间的棋盘,每次可以选择一个矩形把其中的所有格子反色。问把所有格子变成一种颜色时的最少操作次数。
输入描述
第一行一个整数 T(T≤10) 表示数据组数。 每组数据有一行, 两个正整数 n,m(n≤109,m≤109)。
输出描述
对于每组数据输出一行一个整数,代表最少需要的操作次数。
输入样例
3 1 2 2 2 3 3
输出样例
1 2 2
/* BestCoder Round #73 (div.2) hdu5630 Rikka with Chess 思路: 先对行进行翻转,然后对列进行翻转 hhh-2016-02-25 11:27:16 */ #include <functional> #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <map> #include <cmath> using namespace std; typedef long long ll; typedef long double ld; const int maxn = 65; int main() { int T; scanf("%d",&T); while(T--) { int n,m; scanf("%d%d",&n,&m); printf("%d ",n/2 + m/2); } return 0; }