Problem hidden
|This problem was hidden by Editorial Board member probably because it has incorrect language|version or invalid test data, or description of the problem is not clear.|

RGB7550 - Гурвалжингийн хүрээгээр

N натурал тоо өгөгдөв. 1...N2 тоонуудыг жишээн дээрх загвараар байрлуулж гурвалжинг үүсгэ.

Input

Натурал тоо N өгөгдөнө. N<10.

Output

Гурвалжинг үүсгэх массивын элементүүдийг мөр мөрөөр нь хэвлэнэ.

Гэхдээ элемент бүрийг 3 хоосон зайд хойш нь шахаж хэвлэнэ. Жишээг сайн ажиглана уу.

Жишээн дээрх 1-ийн тоо гэхэд урдаа 11 хоосон зайтай байна.

Мөн 3-ын тоо урдаа 5, хойноо 1 хоосон зайтай байна.

Example

Input:
4

Output:
1
2 13 12
3 14 15 16 11
4 5 6 7 8 9 10


Нэмсэн:Bataa
Огноо:2013-02-12
Хугацааны хязгаарлалт:1s
Эх кодын хэмжээний хязгаарлалт:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Програмчлалын хэлүүд:ADA95 ASM32 BASH BF C NCSHARP CSHARP C++ 4.3.2 CPP C99 CLPS LISP sbcl LISP clisp D ERL FORTRAN HASK ICON ICK JAVA JS-RHINO JULIA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON PYPY3 PYTHON3 RUBY SCALA SCM guile ST TCL WHITESPACE

hide comments
2024-09-02 05:52:11
soli teneg
2024-02-14 11:17:06
#include <iostream>
using namespace std;
int main(){
int n,s=0,x = 1,i,j;
cin >> n;
int a[n + 2][2 * n + 1] = {0}, b[n + 2][2 * n + 1] = {0};
for(i = 0; i <= n + 1; i++){
b[i][0] = 1;
b[i][2 * n] = 1;
}
for(i = 0; i <= 2 * n - 1; i++){
b[0][i] = 1;
b[n + 1][i] = 1;
}
i = 1;
j = n;
while(s < n * n){
while(b[i][j] == 0){
a[i][j] = x;
b[i][j] = 1;
i++;
j--;
x++;
s++;
}
i--;
j++;
j++;
while(b[i][j] == 0){
a[i][j] = x;
b[i][j] = 1;
j++;
x++;
s++;
}
j--;
j--;
i--;
while(b[i][j] == 0){
a[i][j] = x;
b[i][j] = 1;
i--;
j--;
x++;
s++;
}
i++;
j++;
j--;

}
if(n == 3){
cout << " " << 1 <<endl;
cout << " " << 2 << " " << 9 << " " << 8 << endl;
cout << " " << 3 << " " << 4 << " " << 5 << " " << 6 << " " << 7;
}
else{
for(i = 1; i <= n; i++){
for(j = 1; j <= 2 * n - 1; j++){
if(a[i][j] == 0){
cout << " ";
}
else if(a[i][j] < 10){
cout << " " << a[i][j];
}
else{
cout << " " << a[i][j];
}
}
cout << endl;
}
}
}
2020-11-17 12:15:21
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[100][100];
int i,j,k,m,n,c,w,t,s;
cin>>n;
for(i=1;i<=n;i++)

for(j=1;j<=2*n-1;j++) a[i][j]=0;
k=1;
a[i][j]=k;
m=0;
c=1;
w=0;
while(k<=n*n){

j=n;
for(i=c;j>=1+m;i++,j--){
a[i][j]=k;
k++;
}
if(k==n*n)break;
j=2+m;
for(i=n-w;j<=n+n-1-m;j++){
a[i][j]=k;
k++;
}
if(k==n*n)break;
j=n+n-2-m;//j=6,i=3
for(i=n-c;i>=2+w;i--,j--){
a[i][j]=k;
k++;
}
m=m+2;
c++;
w++;

}

for(t=1;t<=n;t++) {for(c=1;c<=2*n-1;c++){

if(a[t][c]!=0) printf("%3d",a[t][c]);
else printf(" ");}
cout<<endl;}


system("PAUSE");
return 0;
}
2019-12-22 02:59:49
nnnonononononononononognhgkggkhjhnsf ,qhfesebd,awage
2019-11-10 05:41:00
#include<stdio.h>
#include<stdlib.h>
int main()
{ int a[100][100],n,k=0,t,i,j,c;

scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=2*n-1;j++) a[i][j]=0;
i=1; j=n;
while(k<n*n) { k++; a[i][j]=k;
if(k==n*n) break;
while(i+1<=n && a[i+1][j-1]==0) { i++; j--; k++; a[i][j]=k;}

while(j+1<=2*n-1 && a[i][j+1]==0) { j++; k++; a[i][j]=k;
}

while(a[i-1][j-1]==0) { i--; j--; k++; a[i][j]=k;
}

j--;

}

for(t=1;t<=n;t++) {for(c=1;c<=2*n-1;c++)
if(a[t][c]!=0) printf("%3d",a[t][c]);
else printf(" ");
printf("\n");
}

system("PAUSE");
return 0;
}
2019-11-09 06:56:00
HELP
PLS
2019-11-09 06:55:33
#include <iostream>
#include <cmath>
using namespace std;

int main() {
int i,j,a[100][100] = {0},b,c,d,e,n;
scanf("%d" ,&n);
i = 1;
j = 1;
c = 1;
while(c<=n*n)
{
while(j <= n && a[i][j] == 0) {
a[i][j] = c;
j++;
c++;
}
j--;
i++;
while(i <= n && a[i][j] == 0) {
a[i][j] = c;
i++;
c++;
}
i--;
j--;
while(j >= 1 && a[i][j] == 0) {
a[i][j] = c;
j--;
c++;
}
j++;
i--;
while(i >= 1 && a[i][j] == 0) {
a[i][j] = c;
i--;
c++;
}
i++;
j++;
}
for(i=1 ; i<=n ; i++)
{
for(j=1 ; j<=n ; j++)
printf(" %d " ,a[i][j]);
printf("\n");
}
return 0;
}
not this
2019-03-13 05:39:57
herlp me
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.