当前位置:网站首页>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;
}边栏推荐
- 长度为n的入栈顺序的可能出栈顺序种数
- 在线文本行固定长度填充工具
- Threejs Internet of things, 3D visualization of farm (III) model display, track controller setting, model moving along the route, model adding frame, custom style display label, click the model to obt
- Rome链分析
- 25K 入职腾讯的那天,我特么哭了
- MySQL: view with subquery in the from clause limit
- Is "golden nine and silver ten" the best time to find a job? Not necessarily
- Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
- Behavior perception system
- The scale of computing power in China ranks second in the world: computing is leaping forward in Intelligent Computing
猜你喜欢

Containerd series - detailed explanation of plugins

技术教程:如何利用EasyDSS将直播流推到七牛云?
![[understand series after reading] 6000 words teach you to realize interface automation from 0 to 1](/img/eb/c944d4a71ce30589e71059ed848899.png)
[understand series after reading] 6000 words teach you to realize interface automation from 0 to 1

Rust blockchain development - signature encryption and private key public key

Use of vscode software
![[phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)](/img/eb/a93630aff7545c6c3b71dcc9f5aa61.png)
[phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)

Uni app common functions /api

我国算力规模排名全球第二:计算正向智算跨越

Plasticscm enterprise crack

Behavior perception system
随机推荐
On the day 25K joined Tencent, I cried
The order of LDS links
Uni app common functions /api
Longyuan war "epidemic" 2021 network security competition web easyjaba
[understand series after reading] 6000 words teach you to realize interface automation from 0 to 1
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
Use threejs to create geometry, dynamically add geometry, delete geometry, and add coordinate axes
What is the reason why the webrtc protocol video cannot be played on the easycvr platform?
这是一个不确定的时代
Rust区块琏开发——签名加密与私钥公钥
error Couldn‘t find a package. JSON file in "your path“
A real day for Beijing programmers!!!!!
Why can't all browsers on my computer open web pages
Learning MVVM notes (1)
小程序中实现文章的关注功能
快手、抖音、视频号交战内容付费
【FineBI】使用FineBI制作自定义地图过程
[brush questions] BFS topic selection
BDF application - topology sequence
Threejs rendering obj+mtl model source code, 3D factory model