当前位置:网站首页>蛇形矩阵
蛇形矩阵
2022-07-05 04:08:00 【学习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){
// 判断横着还是竖着
if(j < n-1)
j++;
else
i++;
s[i][j] = ans++;
//左下
while(j>0 && i < n-1){
j--;i++;
s[i][j] = ans++;
}
// 判断横着还是竖着
if(i < n-1)
i++;
else
j++;
s[i][j] = ans++;
//右上
while(i>0 && j<n-1){
j++;i--;
s[i][j] = ans++;
}
}
init();
return 0;
}边栏推荐
- 小程序中实现文章的关注功能
- MindFusion. Virtual Keyboard for WPF
- Longyuan war "epidemic" 2021 network security competition web easyjaba
- 根据入栈顺序判断出栈顺序是否合理
- 为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?
- Scheduling system of kubernetes cluster
- How to realize real-time audio and video chat function
- Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
- 面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
- 长度为n的入栈顺序的可能出栈顺序
猜你喜欢

How does the applet solve the rendering layer network layer error?

Is "golden nine and silver ten" the best time to find a job? Not necessarily

The scale of computing power in China ranks second in the world: computing is leaping forward in Intelligent Computing

为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?

【虚幻引擎UE】实现测绘三脚架展开动画制作

如何实现实时音视频聊天功能

Technical tutorial: how to use easydss to push live streaming to qiniu cloud?

3. Package the bottom navigation tabbar

What is the reason why the webrtc protocol video cannot be played on the easycvr platform?

UI automation test farewell to manual download of browser driver
随机推荐
Containerd series - detailed explanation of plugins
Online text line fixed length fill tool
陇原战“疫“2021网络安全大赛 Web EasyJaba
Plasticscm enterprise crack
FFmepg使用指南
Use object composition in preference to class inheritance
Use threejs to create geometry and add materials, lights, shadows, animations, and axes
线上故障突突突?如何紧急诊断、排查与恢复
Uni app change the default component style
技术教程:如何利用EasyDSS将直播流推到七牛云?
【虚幻引擎UE】实现UE5像素流部署仅需六步操作少走弯路!(4.26和4.27原理类似)
Rome链分析
Longyuan war "epidemic" 2021 network security competition web easyjaba
【看完就懂系列】一文6000字教你从0到1实现接口自动化
Three level linkage demo of uniapp uview u-picker components
Threejs rendering obj+mtl model source code, 3D factory model
Sequelize. JS and hasmany - belongsto vs hasmany in serialize js
About the recent experience of writing questions
Mixed compilation of C and CC
UI automation test farewell to manual download of browser driver