当前位置:网站首页>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;
}
边栏推荐
- 技术教程:如何利用EasyDSS将直播流推到七牛云?
- Threejs realizes sky box, panoramic scene, ground grass
- EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
- ClickPaaS低代码平台
- Summary of scene design
- 快手、抖音、视频号交战内容付费
- error Couldn‘t find a package. JSON file in "your path“
- Plasticscm enterprise crack
- [Chongqing Guangdong education] 2408t Chinese contemporary literature reference test in autumn 2018 of the National Open University
- Technical tutorial: how to use easydss to push live streaming to qiniu cloud?
猜你喜欢
Network security - record web vulnerability fixes
Online text line fixed length fill tool
为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?
【虚幻引擎UE】实现UE5像素流部署仅需六步操作少走弯路!(4.26和4.27原理类似)
How to use jedis of redis
Threejs Internet of things, 3D visualization of farms (I)
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
技术教程:如何利用EasyDSS将直播流推到七牛云?
Containerd series - what is containerd?
How to solve the problem that easycvr changes the recording storage path and does not generate recording files?
随机推荐
C language course setting: cinema ticket selling management system
Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
IronXL for . NET 2022.6
A應用喚醒B應該快速方法
【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
Threejs implements labels and displays labels with custom styles
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
【看完就懂系列】一文6000字教你从0到1实现接口自动化
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
Study notes 7
Uni app change the default component style
Looking back on 2021, looking forward to 2022 | a year between CSDN and me
Get to know MySQL connection query for the first time
【虚幻引擎UE】实现背景模糊下近景旋转操作物体的方法及踩坑记录
This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
Wechat applet development process (with mind map)
error Couldn‘t find a package. JSON file in "your path“
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
As soon as I write the code, President Wang talks with me about the pattern all day
Scheduling system of kubernetes cluster