题意:给定一个两个数M,N,表示有N个1,N个2,一直到N个M,现在要求将这些数排列成一个M*N的矩阵,使得任意一行的两个相邻值差值不大于1,每一列没有两个相同的数。

解法:直接输出M,M,M-1,M-1...这样的一个序列之和即可。

代码如下:

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;

int M, N;

int main() {
    while (scanf("%d %d", &M, &N) != EOF) {
        int ret = 0;
        for (int i = 2; i < N; i += 2) {
            ret += M * 2;
            --M;
        }
        printf("%d\n", ret + M);
    }
    return 0;
}

 

相关文章:

  • 2022-01-26
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-07-25
  • 2021-06-18
猜你喜欢
  • 2021-12-31
  • 2022-02-16
  • 2021-12-26
  • 2021-09-26
  • 2022-12-23
相关资源
相似解决方案