当前位置:网站首页>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;
}
边栏推荐
- Explain AI accelerator in detail: why is this the golden age of AI accelerator?
- Libcblas appears when installing opencv import CV2 so. 3:cannot open shared object file:NO such file or directory
- Contest3145 - the 37th game of 2021 freshman individual training match_ G: Score
- [UE4] parse JSON string
- Unspeakable Prometheus monitoring practice
- Node solves cross domain problems
- [untitled] the relationship between the metauniverse and digital collections
- Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
- What is cloud primordial?
- Keepalived set the master not to recapture the VIP after fault recovery (it is invalid to solve nopreempt)
猜你喜欢
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
PHP database connection succeeded, but data cannot be inserted
Redis notes (I) Linux installation process of redis
MySQL is dirty
Kiss number + close contact problem
Network byte order
Imperial cms7.5 imitation "D9 download station" software application download website source code
There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
What are the virtual machine software? What are their respective functions?
Database concept and installation
随机推荐
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
Network communication basic kit -- IPv4 socket structure
Bugku Zhi, you have to stop him
How to use websocket to realize simple chat function in C #
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
New year's first race, submit bug reward more!
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
Short math guide for latex by Michael downs
1day vulnerability pushback skills practice (3)
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
Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
PMP 考試常見工具與技術點總結
WordPress collection WordPress hang up collection plug-in
Résumé des outils communs et des points techniques de l'examen PMP
Rhcsa day 3
What are the conditions for the opening of Tiktok live broadcast preview?
[untitled]
STM32 key content