zoukankan      html  css  js  c++  java
  • Rikka with Chess(规律)

    Rikka with Chess

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 84    Accepted Submission(s): 72

    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
     
     
    题解:很好找的规律,第二组数据:
    101
    010
    101
    把第二行反转
    101
    101
    101
    把第二列反转
    111
    111
    111
    由此可得:
    直接行列减半取整即可;
    代码:
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<vector>
    using namespace std;
    const int INF=0x3f3f3f3f;
    #define mem(x,y) memset(x,y,sizeof(x))
    #define SI(x) scanf("%d",&x)
    #define PI(x) printf("%d",x)
    #define SD(x,y) scanf("%lf%lf",&x,&y)
    #define P_ printf(" ")
    const int MAXN=1010;
    typedef long long LL;
    int main(){
        int T,N,M;
        SI(T);
        while(T--){
            SI(N);
            SI(M);
            printf("%d
    ",N/2+M/2);
        }
        return 0;
    }
  • 相关阅读:
    jmeter对数据库进行简单的压测
    数据库语言sql
    (二)变量的概念与分类
    (一)Java关键字与标识符
    socket之远程执行命令
    python文件操作
    UDP基础server与client
    TCP基础server与client
    Python 之 杂谈(迭代器iter)、偏函数
    python 之解决socket 粘包
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5204376.html
Copyright © 2011-2022 走看看