zoukankan      html  css  js  c++  java
  • 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.
     
    Input
    The first line contains a number T(T10) ——The number of the testcases.

    Each testcase contains two numbers n,m(n109,m109).
     
    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
    ",k);
    	}
    	return 0;
    } 
    

      

  • 相关阅读:
    hbase shell-namespace(命名空间指令)
    hbase shell-general(常规指令)
    hbase shell概述
    Codeforces Round #412 div2 ABCD
    Educational Codeforces Round 19
    CSU 1786 莫队+KDTree
    cdq分治入门and持续学习orz
    VK Cup 2017
    HRBUST 2072 树上求最大异或路径值
    UvaLive 5811 概率DP
  • 原文地址:https://www.cnblogs.com/tonghao/p/5211091.html
Copyright © 2011-2022 走看看