B1105 Spiral Matrix (画图)
B1105 Spiral Matrix (25分)
//第一次只拿了21分
- 矩阵的长和宽,求最大因子,从sqrt(num)开始枚举.
- 每次循环一次,s++,t--,d--,r++
- 测试点四运行超时,是因为输入一个数字的时候,需要直接输出这个数字。//1分
- 测试点二运行超时,最后一个数字不必再while循环一次,直接输出即可。//3分
最后一个测试点卡了好久/(ㄒoㄒ)/~~
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#define lowbit(i)((i)&(-i))
using namespace std;
typedef long long ll;
const int MAX=10010;
const int INF=0x3f3f3f3f;
const int MOD=1000000007;
const int SQR=633;
int mp[1001][1001];
int a[MAX];
bool cmp(int a,int b)
{return a>b;
}
int main()
{int num,m,n,k;scanf("%d",&num);for(int i=1;i<=num;i++){scanf("%d",&a[i]);}
//测试点4if(num==1){cout<<a[1]<<endl;return 0;}sort(a+1,a+num+1,cmp);k=(int)sqrt(1.0*num);while(num%k!=0){k++;}m=k;n=num/k;if(n>m)swap(m,n);
//m行n列int d=m,t=n,j=1,now=1,i=1,r=1,s=1;while(now<=num){while(now<=num&&j<t){mp[i][j]=a[now++];j++;}while(now<=num&&i<d){mp[i][j]=a[now++];i++;}while(now<=num&&j>r){mp[i][j]=a[now++];j--;}while(now<=num&&i>s){mp[i][j]=a[now++];i--;}t--,d--,r++,s++;j++,i++;
//测试点2if(now==num)mp[i][j]=a[now++];}for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){if(j==1)cout<<mp[i][j];elsecout<<" "<<mp[i][j];}cout<<endl;}return 0;
}
B1105 Spiral Matrix (画图)相关推荐
- LeetCode:Spiral Matrix I II
Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matri ...
- LeetCode 59 Spiral Matrix II(螺旋矩阵II)(Array)
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/5214 ...
- LeetCode Spiral Matrix II (生成螺旋矩阵)
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. F ...
- 59. Spiral Matrix II
/** 59. Spiral Matrix II * 12.5 by Mingyang* 注意,这里我们说的Matrix就是正方形,不再是长方形了,所以我们会用* 更简单的方法,就是直接上下左右分别加 ...
- Spiral Matrix I II
Spiral Matrix I Given an integer n, generate a square matrix filled with elements from 1 to n^2 in s ...
- C#LeetCode刷题之#59-螺旋矩阵 II(Spiral Matrix II)
目录 问题 示例 分析 问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3678 访问. 给定一个正整数 n,生成一 ...
- C#LeetCode刷题之#54-螺旋矩阵(Spiral Matrix)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3672 访问. 给定一个包含 m x n 个元素的矩阵(m 行, ...
- PAT1105:Spiral Matrix
1105. Spiral Matrix (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This ti ...
- LeetCode 59. Spiral Matrix II
59. Spiral Matrix II Given an integer n, generate a square matrix filled with elements from 1 to n2 ...
- LeetCode 54. Spiral Matrix
54. Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the m ...
最新文章
- 这本1900页的机器学习数学全书火了!完整版开放下载
- 原创 | 比新基建还火,数字孪生究竟有哪些应用价值?
- verilog中如何拆分一个数
- Semaphore 源码分析
- 学习c++的优秀博客(转)
- lepus mysql 复制监控_MySQL数据库之CentOS搭建lepus3.8监控MySQL
- linux下解压大于4G文件提示error: Zip file too big错误的解决办法
- java web 邮箱激活 与 忘记密码(重置密码)
- WPF Slider设置整数
- App后台开发运维和架构实践学习总结(5)——App产品从需求到研发到开发到上线到产品迭代全过程
- php 背单词系统_《PHP 编程词典(珍藏版)》
- PHP学习笔记01——基础语法
- Hadoop数据读写原理
- solidworks 之迈迪同步轮尺寸与设计不复的解决
- linux 常用软件推荐
- 如何将硬盘数据迁移包括系统一起迁移到另一个硬盘?
- ffmpeg录制桌面,麦克风和系统声音独立成2路音轨
- ftp工具破解版,你知道有哪几款好用的ftp工具破解版吗
- excel表格如何拆分数据
- 千岛湖-印象中的天堂游记