24: Serpentine padding array
- View
- Submit
- Statistics
- Questions
-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
Describe
-
With digital 1,2,3,4,..., n*n This n2 number of snakes filled with the scale of N*n Square.
The Serpentine Fill method is:
For each lower left-right diagonal, numbered from top left to bottom right,..., 2n-1; According to the order from small to large, the numbers from small to large to fill in each slash, where numbered odd from the left to the right to fill, numbered even from the top right to the left to fill.
For example, when n=4, the square is filled with the following form:
1 2 6 73 5 8 134 9 12 1410 11 15 16
-
Input
-
Enter a positive integer not greater than 10 N, representing the number of rows of the square.
-
Output
-
The matrix is output, with a single space interval between adjacent two elements.
-
Sample input
-
4
-
Sample output
-
1 2 6 73 5 8 134 9 12 1410 11 15 16
- View
- Submit
- Statistics
- Questions
1#include <iostream>2#include <cstdio>3#include <string>4#include <cstring>5 using namespacestd;6 inta[101][101];7 intMain ()8 {9 intn,t=0;TenCin>>N; One for(intk=1; k<=n*2-1; k++) A { - if(k%2!=0)//odd Diagonal; - { the for(inti=n;i>=1; i--) - { - for(intj=1; j<=n;j++) - { + if(i+j-1==k) - { +a[i][j]=++T; A } at } - } - } - if(k%2==0) - { - for(intI=1; i<=n;i++) in { - for(intj=1; j<=n;j++) to { + if(i+j-1==k) - { thea[i][j]=++T; * } $ Panax Notoginseng } - } the } + } A for(intI=1; i<=n;i++) the { + for(intj=1; j<=n;j++) - { $cout<<A[i][j]; $cout<<" "; - } -cout<<Endl; the } -}
24: Serpentine padding array