zoukankan      html  css  js  c++  java
  • [CF12E] Start of the season

    [CF12E] Start of the season - 构造

    Description

    构造一个 n×n 的矩阵(n 为偶数),矩阵应该包含 0~n-1 的正整数,主对角线上的数应该都是 0,且整个矩阵应该都是对称的,每行每列上的数都是不同的。

    Solution

    0 1 3 2
    1 0 2 3
    3 2 0 1
    2 3 1 0
    

    把 (i,i) 换成 (i,n) 也就是 (n,i) 后

    2 1 3
    1 3 2
    3 2 1
    

    喜欢的旋转排列出现了

    所以我们先构造 n-1 阶的旋转排列,然后把 (i,i) 放到 (i,n) 和 (n,i) 的位置上

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        int n;
        cin >> n;
    
        vector<vector<int>> a(n + 2, vector<int>(n + 2));
        for (int i = 1; i < n; i++)
            a[1][i] = i;
        for (int i = 2; i < n; i++)
        {
            for (int j = 1; j < n; j++)
                a[i][j] = a[i - 1][j + 1];
            a[i][n - 1] = a[i - 1][1];
        }
        for (int i = 1; i < n; i++)
            a[i][n] = a[n][i] = a[i][i], a[i][i] = 0;
    
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
                cout << a[i][j] << " ";
            cout << endl;
        }
    }
    
  • 相关阅读:
    CodeForces
    CodeForces
    AtCoder
    AtCoder
    CodeForces
    CodeForces
    CodeForces
    CodeForces
    Centos7配置yum国内镜像及仓库升级
    环境变量
  • 原文地址:https://www.cnblogs.com/mollnn/p/14404075.html
Copyright © 2011-2022 走看看