当前位置:网站首页>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;
}
边栏推荐
- Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
- 【虛幻引擎UE】實現UE5像素流部署僅需六步操作少走彎路!(4.26和4.27原理類似)
- Realize the attention function of the article in the applet
- lds链接的 顺序问题
- How does the applet solve the rendering layer network layer error?
- Kwai, Tiktok, video number, battle content payment
- UI自動化測試從此告別手動下載瀏覽器驅動
- Threejs rendering obj+mtl model source code, 3D factory model
- [charging station]_ Secular wisdom_ Philosophical wisdom _
- 我就一写代码的,王总整天和我谈格局...
猜你喜欢
Realize the attention function of the article in the applet
JVM garbage collection
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
Containerd series - what is containerd?
Learning notes 8
10种寻址方式之间的区别
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
“金九银十”是找工作的最佳时期吗?那倒未必
【刷题】BFS题目精选
Alibaba cloud ECS uses cloudfs4oss to mount OSS
随机推荐
小程序中实现文章的关注功能
基于TCP的移动端IM即时通讯开发仍然需要心跳保活
On the day 25K joined Tencent, I cried
Deflocculant aminoiodotide eye drops
Threejs realizes rain, snow, overcast, sunny, flame
我国算力规模排名全球第二:计算正向智算跨越
Pyqt5 displays file names and pictures
Pyqt pyside custom telescopic menu bar sharing (including tutorial)
kubernetes集群之调度系统
Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
Threejs Internet of things, 3D visualization of farms (I)
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
Seven join join queries of MySQL
UI自動化測試從此告別手動下載瀏覽器驅動
Use threejs to create geometry and add materials, lights, shadows, animations, and axes
Threejs factory model 3DMAX model obj+mtl format, source file download
3. Package the bottom navigation tabbar
Looking back on 2021, looking forward to 2022 | a year between CSDN and me
A real day for Beijing programmers!!!!!
Possible stack order of stack order with length n