BestCoder Round #73 (div.2)(hdu 5630)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BestCoder Round #73 (div.2)(hdu 5630)相关的知识,希望对你有一定的参考价值。
Rikka with Chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 177 Accepted Submission(s): 161
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.
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).
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的黑白相间的矩形,每次可以从这个矩形中选出一个任意长宽的矩形,将其中的格子反色,问最少操作几次使所有的格子颜色相同
题解:画出图形可以发现规律两行之间上下格子的颜色刚好反色,这样我们将任意一行反色即可使两行上下格子同色,这样我们操作了m/2次,操作完毕后,每一列的格子都同色 但是相邻的两列反色 此时我们将反色的格子反转颜色即可即n/2,所以答案是n/2+m/2
#include<stdio.h> #include<string.h> #include<math.h> #include<stack> #include<queue> #include<math.h> #include<algorithm> #define MAX 10010 #define INF 0x7ffff #define MAXM 100100 #define LL long long using namespace std; int main() { int t,n,m,k; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); k=n/2+m/2; printf("%d\n",k); } return 0; }
以上是关于BestCoder Round #73 (div.2)(hdu 5630)的主要内容,如果未能解决你的问题,请参考以下文章
BestCoder Round #69 (div.2)(hdu5611)