PAT basic 1050
来源:互联网 发布:跨运营商之间网络不通 编辑:程序博客网 时间:2024/06/06 09:24
#include <cmath>#include <vector>#include <cstdio>#include <algorithm>using namespace std;int func(int N) { int i = sqrt((double)N); while(i >= 1) { if(N % i == 0) return i; i--; } return 1;}int cmp(int a, int b) {return a > b;}int main() { int N, m, n, t = 0; scanf("%d", &N); n = func(N); m = N / n; vector<int> a(N); for (int i = 0; i < N; i++) scanf("%d", &a[i]); sort(a.begin(), a.end(), cmp); vector<vector<int> > b(m, vector<int>(n)); //相当于一个m行n列的矩阵 int level = 1000;//不过其实是多少都无伤大雅//int level = n / 2 + n % 2;//这才是正确的逻辑 //int level = m / 2 + m % 2; for (int i = 0; i < level; i++) { for (int j = i; j <= n - 1 - i && t <= N - 1; j++) { b[i][j] = a[t++]; } for (int j = i + 1; j <= m - 2 - i && t <= N - 1; j++) { b[j][n - 1 - i] = a[t++]; } for (int j = n - i - 1; j >= i && t <= N - 1; j--) { b[m - 1 - i][j] = a[t++]; } for (int j = m - 2 - i; j >= i + 1 && t <= N - 1; j--) { b[j][i] = a[t++]; } } for (int i = 0; i < m; i++) { for (int j = 0 ; j < n; j++) { printf("%d", b[i][j]); if (j != n - 1) printf(" "); } printf("\n"); } return 0;}
阅读全文
0 0
- pat-basic-1050
- PAT basic 1050
- PAT Basic
- PAT (Basic Level) Practise
- PAT Basic 1001
- PAT Basic 1002
- PAT Basic 1005
- PAT Basic 1006
- PAT Basic 1007
- PAT Basic 1008
- PAT Basic 1009
- PAT Basic 1010
- pat basic level 1016
- pat basic level 1018
- pat basic level 1019
- PAT(basic level)题解
- PAT basic 1004 : 成绩排名
- PAT (Basic) 1001~1005
- java解析xml文件并获取子节点
- next_permutation函数和prev_permutation函数
- Configuration--mappers--XMLMapperBuilder.parse(三-8-2)
- IT人士必备网站
- 简单视察特效的实现
- PAT basic 1050
- HDU 6165 FFF at Valentine
- canvas标签
- .NET Core 2.0 开源Office组件 NPOI
- JIRA 7.2.2破解版 服务端安装
- android HDMI (一):HDMI基础篇
- Codeforces AIM Tech Round 3 (Div. 2)(A-D 未完)
- 利用htmlunit——WebClient实现的java爬虫程序
- 1007(优先队列)