BestCoder Round #73 (div.2)(hdu 5630)
2016-02-23 20:14
323 查看
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
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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).
[align=left]Output[/align]
For each testcase, print a single number which represents the answer.
[align=left]Sample Input[/align]
3
1 2
2 2
3 3
[align=left]Sample Output[/align]
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; }
相关文章推荐
- MyBatis 拦截器 (实现分页功能)
- 二叉树——根据二叉树遍历序列构造二叉树
- YTU 2426: C语言习题 字符串排序
- ->的使用
- Rcpp实用手册
- 杂谈-环境
- vim 配置
- EL表达式中的四个范围
- SpringMVC 406 accept请求错误,没有加入将json序列化的包
- nginx
- SVN操作 -- TortoiseSVN中的Excel文件比较
- 基于Servlet&Jsp的网上书店设计(三)
- Introduction the naive“scull” 《linux设备驱动》 学习笔记
- 立体匹配:关于OpenCV读写middlebury网站的给定的视差并恢复三维场景的代码
- 【cin】练习
- android 自定义圆形ProgressBar
- Emoji 表情
- php错误提示 open_basedir restriction in effect 解决
- 沉没成本——无法收回的成本,但不要影响下一次决策
- read access violation at:0x0, flags=0x0(first chance)