标签:bre out mes col 螺旋矩阵 ios ble for href
1050 螺旋矩阵 (25分)
https://pintia.cn/problem-sets/994805260223102976/problems/994805275146436608
https://paste.ubuntu.com/p/Dn7fQ9Gf73/
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <vector> using namespace std; int main() { int n,x,y; cin>>n; vector<int> vec(n); for(int i=0;i<n;i++) cin>>vec[i]; sort(vec.begin(),vec.end(),greater<int>()); for(int i=(int)(sqrt(n)+0.5);i>=1;i--){ if(n%i==0){ x=i; y=n/i; break; } } int i=-1,j=-1,k=-1,arr[y][x]; for(i=0;k<y*x-1;i++) { for(j=i;j<x-i&&k<y*x-1;j++) arr[i][j]=vec[++k]; for(j=i+1;j<y-i&&k<y*x-1;j++) arr[j][x-i-1]=vec[++k]; for(j=x-i-2;j>=i&&k<y*x-1;j--) arr[y-i-1][j]=vec[++k]; for(j=y-i-2;j>=i+1&&k<y*x-1;j--) arr[j][i]=vec[++k]; } for(i=0;i<y;i++) { for(j=0;j<x;j++) { if(j==0) cout<<arr[i][j]; else cout<<" "<<arr[i][j]; } cout<<endl; } return 0; }
标签:bre out mes col 螺旋矩阵 ios ble for href
原文地址:https://www.cnblogs.com/jianqiao123/p/12287902.html