Rikka with Chess
Description
Yuta gives Rikka a chess board of size
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7bc7a46903e8e00cbfe6cbe17b29ce9b.png)
.
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.
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7bc7a46903e8e00cbfe6cbe17b29ce9b.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
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
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
――The number of the testcases.
Each testcase contains two numbers![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/094f0c54ab74a17baaa3bd2c27e2cbb6.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/094f0c54ab74a17baaa3bd2c27e2cbb6.png)
.
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9f61591de1c8a8c5f8c7d228814838c5.png)
Each testcase contains two numbers
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/094f0c54ab74a17baaa3bd2c27e2cbb6.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f9c38887f58a15d10c8b7e0e22ef29a9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/094f0c54ab74a17baaa3bd2c27e2cbb6.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9f61591de1c8a8c5f8c7d228814838c5.png)
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 的棋盘(类似于国际象棋的棋盘),上下左右相邻的格子颜色不同(黑和白),有一个人可以一次操作任意规格矩形内的格子,使得其颜色变成另一种颜色,问这个人想把棋盘操作成只有一种颜色,最少需要操作几次
题解:
根据图形的特殊性,每次只操作一行或者一列才可能最优,不难发现,每次操作的话,最少需要n/2次 行的操作,就能使得所有相同颜色的在同一列,然后对m/2列进行操作,既能使得所有的格子颜色相同。
#include<stdio.h>
#include<string.h>
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;
}