1050. 螺旋矩阵(25)
来源:互联网 发布:子弹算法 编辑:程序博客网 时间:2024/06/03 17:03
非常易错的一道题。核心的考点就在所开数组空间的问题上。只能说长见识了吧。
// 2017/10/14 NCU // PAT-B 1053// scienceZ#include <cstdio>#include <cmath>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;int N, m, n;int store[10100];int arr[10010][10010];void solve(){ int i = 1, j = 1; arr[i][j] = store[N-1]; N--; while(N-1>=0){ while(j < n && arr[i][j+1] == 0) { arr[i][++j] = store[N-1]; N--; } while(i < m && arr[i+1][j] == 0) { arr[++i][j] = store[N-1]; N--; } while(j > 1 && arr[i][j-1] == 0) { arr[i][--j] = store[N-1]; N--; } while(i > 1 && arr[i-1][j] == 0) { arr[--i][j] = store[N-1]; N--; } } return;}int main(){ cin >> N; for (int i = 0; i<N; i++) cin >> store[i]; sort(store, store+N); n = floor(sqrt(N)); m = N/n; while(n*m != N){ n--; m = N/n; } solve(); for(int i = 1; i<=m; i++){ for (int j = 1; j<=n-1; j++) printf("%d ", arr[i][j]); printf("%d\n", arr[i][n]); } return 0;}
阅读全文
0 0
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- 1050. 螺旋矩阵(25)
- Intellij IDEA Debug调试方法
- React Native 混合编程 之访问iOS设备
- MySql学习记录4-字符串处理函数
- python之实战----广义线性模型
- 使用vscode 开发electron 之 启动配置
- 1050. 螺旋矩阵(25)
- python 按照字典的值进行排序
- 国内暂时可用的API集合
- 思科路由模拟器 -- (3)RIP协议及配置
- KMS激活脚本生成程序(自用备份)
- 选太子问题
- 【安全牛学习笔记】初识sql注入漏洞原理
- Spring中AOP的JDKProxy和CGlibProxy的区别
- MySQL 常用指令小结