当前位置:网站首页>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;
}
边栏推荐
- JS object definition
- What is the difference between enterprise wechat applet and wechat applet
- 2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
- The property of judging odd or even numbers about XOR.
- Global and Chinese market of thin film deposition systems 2022-2028: Research Report on technology, participants, trends, market size and share
- There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
- Development of digital collection trading platform development of digital collection platform
- Want to do something in production? Then try these redis commands
- Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
- 2022 attached lifting scaffold worker (special type of construction work) free test questions and attached lifting scaffold worker (special type of construction work) examination papers 2022 attached
猜你喜欢

1day vulnerability pushback skills practice (3)

The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"

Development of digital collection trading platform development of digital collection platform

Ai aide à la recherche de plagiat dans le design artistique! L'équipe du professeur Liu Fang a été embauchée par ACM mm, une conférence multimédia de haut niveau.

Dare to climb here, you're not far from prison, reptile reverse actual combat case

New year's first race, submit bug reward more!
![[latex] production of complex tables: excel2latex and detail adjustment](/img/39/0d448ddf006eda262de3ed75666354.jpg)
[latex] production of complex tables: excel2latex and detail adjustment

What is the difference between enterprise wechat applet and wechat applet

Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex

Node write API
随机推荐
Latex tips slash \backslash
長文綜述:大腦中的熵、自由能、對稱性和動力學
Global and Chinese market of cell scrapers 2022-2028: Research Report on technology, participants, trends, market size and share
Sword finger offer:55 - I. depth of binary tree
Unity knapsack system (code to center and exchange items)
This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
I stepped on a foundation pit today
Career development direction
Global and Chinese markets for electroencephalogram (EEG) devices 2022-2028: Research Report on technology, participants, trends, market size and share
Libcblas appears when installing opencv import CV2 so. 3:cannot open shared object file:NO such file or directory
static hostname; transient hostname; pretty hostname
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
Problems and solutions of several concurrent scenarios of redis
Rhcsa day 2
Explain AI accelerator in detail: why is this the golden age of AI accelerator?
Teach you how to optimize SQL
Eh, the log time of MySQL server is less than 8h?
Learning video website
There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
Experience summary of the 12th Blue Bridge Cup (written for the first time)