PAT乙级—1050
2018-03-10 22:21
190 查看
#include <iostream> #include <vector> #include <algorithm> #include <math.h> using namespace std; bool comp(int a, int b){ return a>b; } int main() { int N; int m=0, n=0; cin>>N; for(int i=(int)sqrt(N); i<=N; i++){ if(N%i==0){ m=i; n=N/m; break; } } cout<<n<<' '<<m<<endl; vector<int>v; int a; for(int i=0; i<N; i++){ cin>>a; v.push_back(a); } sort(v.begin(), v.end(), comp); int x=0, y=0, j=0; vector<vector <int>>b; //int b[1000][1000]={0}; while(j<N){ while(y+1<n&&!b[x][y+1]) b[x][++y]=v[++j]; while(x+1<m&&!b[x+1][y]) b[++x][y]=v[++j]; while(y-1>=0&&!b[x][y-1]) b[x][--y]=v[++j]; while(x-1>=0&&!b[x-1][y]) b[--x][y]=v[++j]; } for(int i=0; i<m; i++){ for(int h=0; h<n; h++){ if(h==n-1) cout<<b[i][h]<<endl; else cout<<b[i][h]<<' '; } } return 0; }
相关文章推荐
- 1050. 螺旋矩阵(25) PAT乙级真题
- PAT乙级(Basic Level)1050(C++)
- 乙级 PAT 1050. 螺旋矩阵(25)
- pat乙级1050. 螺旋矩阵(25)
- pat 乙级 1050. 螺旋矩阵(25)
- pat乙级真题 1050. 螺旋矩阵(25)
- PAT 乙级1050. 螺旋矩阵(25)&&蛇形填数&&51Nod 1283 最小的周长
- [PAT-乙级]1050.螺旋矩阵
- PAT考试乙级1050(C语言实现) (重点题目)(关于保留小数的坑)
- PAT乙级 1050 螺旋矩阵(25)
- PAT乙级 1050. 螺旋矩阵(25)
- PAT乙级1050. 螺旋矩阵(25)
- PAT考试乙级1050(C语言实现) (重点题目)(按格式读取,使用容器vector)
- PAT乙级 1050. 螺旋矩阵(25)
- PAT乙级1050 螺旋矩阵
- PAT乙级1050
- PAT 乙级1046-1050
- PAT考试乙级1050(C语言实现) (重点题目)(memset以及思路)
- 1050. 螺旋矩阵(25)-浙大PAT乙级真题java实现
- PAT乙级—1050. 螺旋矩阵(25)-native