其他分享
首页 > 其他分享> > Codeforces 1333 E - Road to 1600 (构造)

Codeforces 1333 E - Road to 1600 (构造)

作者:互联网



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
#define rep(i, a, n) for(int i = a; i <= n; ++ i);
#define per(i, a, n) for(int i = n; i >= a; -- i);
typedef long long ll;
const int N = 5e2 + 105;
const int mod = 998244353;
const double Pi = acos(- 1.0);
const int INF = 0x3f3f3f3f;
const int G = 3, Gi = 332748118;
ll qpow(ll a, ll b) { ll res = 1; while(b){ if(b) res = (res * a) % mod; a = (a * a) % mod; b >>= 1;} return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
//


int n;
int res[N][N];

int main()
{
    scanf("%d",&n);
    if(n < 3){
        printf("-1\n");
        return 0;
    }
    res[1][1] = 4, res[1][2] = 5, res[1][3] = 9;
    res[2][1] = 3, res[2][2] = 2, res[2][3] = 6;
    res[3][1] = 1, res[3][2] = 8, res[3][3] = 7;
    int top = n, num = 0;
    
    while(top > 3){
        if(top % 2 == 0){
            for(int i = 1; i <= top; ++ i) res[i][top] = ++ num;
            for(int i = top - 1; i >= 1; -- i) res[top][i] = ++ num;
        }
        else{
            for(int i = 1; i <= top; ++ i) res[top][i] = ++ num;
            for(int i = top - 1; i >= 1; -- i) res[i][top] = ++ num;
        }
        top --;
    }
    
    for(int i = 1; i <= n; ++ i){
        for(int j = 1; j <= n; ++ j){
            if(i <= 3 && j <= 3) res[i][j] += num;
            if(j == 1) printf("%d",res[i][j]);
            else printf(" %d",res[i][j]);
        }
        printf("\n");
    }
    return 0;
}


标签:int,1600,ll,Codeforces,3x3,res,include,top,Road
来源: https://www.cnblogs.com/A-sc/p/12812615.html