Untitled
#include <bits/stdc++.h> using namespace std; #define Task "test" #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define FORD(i, a, b) for(int i = (a); i <= (b); ++i) #define pb push_back #define pf push_front #define fi first #define se second #define endl "\n" #define int long long #define Chris_No_Luv signed main() typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> vi; typedef vector<int> vii; typedef set<int> viii; typedef map<int, int> viiii; const int mod = (int) 1e9 + 7; const int INF = (int) 1e9 + 2804; int a[11025], dp[105][105],n; Chris_No_Luv { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); if (fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n; int dem = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { dem++; cin >> a[dem]; } sort(a+1, a+dem+1); dem = 0; for (int i = 1; i <= n; i++) { if (i % 2 == 1) for (int j = 1; j <= n; j++) { dem++; dp[i][j] = a[dem]; } else for (int j = n; j >= 1; j--) { dem++; dp[i][j] = a[dem]; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cout << dp[i][j] <<" "; cout << endl; } dem = 0; for (int j = n; j >= 1; j--) { if (j % 2 == n%2) { for (int i = n; i >= 1; i--) { dem++; dp[i][j] = a[dem]; } } else { for (int i = 1; i <= n; i++) { dem++; dp[i][j] = a[dem]; } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cout << dp[i][j] <<" "; cout << endl; } dem = 0; if (n%2==1) dp[n/2+1][n/2+1] = a[n*n]; for (int i = 1; i <= n/2; i++) { for (int j = i; j <= n-i; j++) { dem++; dp[i][j] = a[dem]; } for (int j = i; j <= n-i; j++) { dem++; dp[j][n-i+1] = a[dem]; } for (int j = n-i+1; j > i; j--) { dem++; dp[n-i+1][j] = a[dem]; } for (int j = n-i+1; j > i; j--) { dem++; dp[j][i] = a[dem]; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cout << dp[i][j] <<" "; cout << endl; } dem = 0; int row = 1, col = 1; for (int i = 1; i <= 2*n-1; i++) { if (i % 2 == 1) { for (int j = 1; j <= i; j++) { int row = i+1-j; if (row <= n && j <= n) { dem++; dp[row][j] = a[dem]; } } } else { for (int j = i; j >= 1; j--) { int row = i+1-j; if (row <= n && j <= n) { dem++; dp[row][j] = a[dem]; } } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cout << dp[i][j] <<" "; cout << endl; } }
Leave a Comment