当前位置:网站首页>Zigzag scan
Zigzag scan
2022-07-04 03:18:00 【< WRM>】
#include<bits/stdc++.h>
using namespace std;
const int N = 5500;
int a[N][N];
int visited[N][N];
int dx[4] = {
0, 1, 1, -1};
int dy[4] = {
1, -1, 0, 1};
int result[260000];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &a[i][j]);
visited[i][j] = 0;
}
}
int i = 1, j = 1;
int cunt = 1;
result[cunt] = a[i][j];
int k = 4;
int sum = 0;
visited[1][1] = 1;
while (cunt < n * n) {
//printf("*********\n");
if (i + dx[k % 4] >= 1 && j + dy[k % 4] >= 1 && i + dx[k % 4] <= n && j + dy[k % 4] <= n && !visited[i + dx[k % 4]][j + dy[k % 4]]) {
i = i + dx[k % 4];
j = j + dy[k % 4];
visited[i][j] = 1;
if (k % 4 == 0 || k % 4 == 2) k++;
cunt++;
result[cunt] = a[i][j];
//printf("%d %d %d\n",i,j,cunt);
} else {
k++;
}
}
for (int i = 1; i <= cunt; i++) {
printf("%d ", result[i]);
}
return 0;
}
边栏推荐
- Backpropagation formula derivation [Li Hongyi deep learning version]
- 2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
- Global and Chinese market of box seals 2022-2028: Research Report on technology, participants, trends, market size and share
- 2006 translation
- Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
- PID of sunflower classic
- Solve the problems encountered by the laravel framework using mongodb
- MySQL is dirty
- Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
- Optimization theory: definition of convex function + generalized convex function
猜你喜欢

This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t

Rhcsa day 3

MySQL workbench use

What is the difference between enterprise wechat applet and wechat applet

Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website

Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami

What are the virtual machine software? What are their respective functions?

Node write API
![Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]](/img/0d/7a8370d153a8479b706377c3487220.jpg)
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]

Unity controls the selection of the previous and next characters
随机推荐
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
Webhook triggers Jenkins for sonar detection
Cache general management class + cache httpcontext Current. Cache and httpruntime Differences between caches
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
[database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
基於.NetCore開發博客項目 StarBlog - (14) 實現主題切換功能
Baijia forum the founding of the Eastern Han Dynasty
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
Formulaire day05
Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to
[development team follows] API specification
CSCI 2134
Short math guide for latex by Michael downs
Want to do something in production? Then try these redis commands
A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
PTA tiantisai l1-079 tiantisai's kindness (20 points) detailed explanation
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
Unspeakable Prometheus monitoring practice
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
Consul of distributed service registration discovery and unified configuration management