当前位置:网站首页>Serpentine matrix
Serpentine matrix
2022-07-05 04:11:00 【Learning KL & TK】
#include"bits/stdc++.h"
using namespace std;
int s[105][105];
int n;
void init(){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
printf("%d ",s[i][j]);
cout << endl;
}
}
int main()
{
cin >> n;
int ans = 1;
int i = 0 , j = 0;
s[0][0]=ans++;
while(ans < n*n){
// Judge whether it is horizontal or vertical
if(j < n-1)
j++;
else
i++;
s[i][j] = ans++;
// The lower left
while(j>0 && i < n-1){
j--;i++;
s[i][j] = ans++;
}
// Judge whether it is horizontal or vertical
if(i < n-1)
i++;
else
j++;
s[i][j] = ans++;
// The upper right
while(i>0 && j<n-1){
j++;i--;
s[i][j] = ans++;
}
}
init();
return 0;
}
边栏推荐
- Seven join join queries of MySQL
- Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
- Learning notes 8
- NetSetMan pro (IP fast switching tool) official Chinese version v5.1.0 | computer IP switching software download
- Rust区块琏开发——签名加密与私钥公钥
- Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
- A应用唤醒B应该快速方法
- WGS84 coordinate system, web Mercator, gcj02 coordinate system, bd09 coordinate system - brief introduction to common coordinate systems
- Threejs Internet of things, 3D visualization of factory
- How to use jedis of redis
猜你喜欢
Test d'automatisation de l'interface utilisateur télécharger manuellement le pilote du navigateur à partir de maintenant
kubernetes集群之调度系统
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
在线文本行固定长度填充工具
Wechat applet development process (with mind map)
A real day for Beijing programmers!!!!!
小程序中实现文章的关注功能
技术教程:如何利用EasyDSS将直播流推到七牛云?
Special Edition: spreadjs v15.1 vs spreadjs v15.0
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
随机推荐
Common features of ES6
Ctfshow 2022 Spring Festival welcome (detailed commentary)
Un réveil de l'application B devrait être rapide
Alibaba cloud ECS uses cloudfs4oss to mount OSS
About the recent experience of writing questions
Threejs Internet of things, 3D visualization of farms (I)
C language course setting: cinema ticket selling management system
Pyqt pyside custom telescopic menu bar sharing (including tutorial)
Rome链分析
灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
Network security - record web vulnerability fixes
Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
[understand series after reading] 6000 words teach you to realize interface automation from 0 to 1
Clickpaas low code platform
The scale of computing power in China ranks second in the world: computing is leaping forward in Intelligent Computing
Pyqt5 displays file names and pictures
[array]566 Reshape the matrix - simple
[charging station]_ Secular wisdom_ Philosophical wisdom _
Use object composition in preference to class inheritance