当前位置:网站首页>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;
}
边栏推荐
- Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
- Love and self-discipline and strive to live a core life
- Network communication basic kit -- IPv4 socket structure
- Backpropagation formula derivation [Li Hongyi deep learning version]
- Contest3145 - the 37th game of 2021 freshman individual training match_ J: Eat radish
- Key knowledge of C language
- PTA tiantisai l1-079 tiantisai's kindness (20 points) detailed explanation
- Short math guide for latex by Michael downs
- MySQL is dirty
- New year's first race, submit bug reward more!
猜你喜欢
New year's first race, submit bug reward more!
Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex
Node write API
Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
Jenkins continuous integration environment construction V (Jenkins common construction triggers)
Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?
If you have just joined a new company, don't be fired because of your mistakes
Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
Li Chuang EDA learning notes IX: layers
Crawler practice website image batch download
随机推荐
Want to do something in production? Then try these redis commands
Remote work guide
Pagoda SSL can't be accessed? 443 port occupied? resolvent
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
Jenkins continuous integration environment construction V (Jenkins common construction triggers)
MySQL workbench use
Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
false sharing
Buuctf QR code
SQL injection (1) -- determine whether there are SQL injection vulnerabilities
Safety tips - seat belt suddenly fails to pull? High speed police remind you how to use safety belts in a standardized way
Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?
Contest3145 - the 37th game of 2021 freshman individual training match_ G: Score
Love and self-discipline and strive to live a core life
In my spare time, I like to write some technical blogs and read some useless books. If you want to read more of my original articles, you can follow my personal wechat official account up technology c
Record a problem that soft deletion fails due to warehouse level error
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love
Li Chuang EDA learning notes IX: layers
Global and Chinese market of small batteries 2022-2028: Research Report on technology, participants, trends, market size and share
Key knowledge of C language