#3442
SpiralMatrix
Parcurgând elementele unei matrice pătratice de dimensiune n
în spirală, pornind din colțul din
stânga-sus, în sens orar, de la margini către interior, se obține șirul strict crescător format din toate
valorile de la 1
la n
2
, ca în figura de mai jos. Din șirul dat se obțin două subșiruri disjuncte, de lungime egală, cu număr maxim de termeni. Primul subșir este format din numere consecutive din prima jumătate a șirului, și trebuie să conțină în mod obligatoriu valoarea 1
, iar al doilea este format din numere consecutive din a doua jumătate a șirului și trebuie să conțină în mod obligatoriu valoarea n
2
.
1 | 2 | 3 | 4 | 5 |
16 | 17 | 18 | 19 | 6 |
15 | 24 | 25 | 20 | 7 |
14 | 23 | 22 | 21 | 8 |
13 | 12 | 11 | 10 | 9 |
Să se afle poziția în matrice a celui mai mare termen din primul subșir și a celui mai mic termen din al
doilea subșir.
OJI 2020, clasa a IX-a
Problema | SpiralMatrix | Operații I/O |
![]() spiralmatrix.in /spiralmatrix.out
|
---|---|---|---|
Limita timp | 0.2 secunde | Limita memorie |
Total: 64 MB
/
Stivă 32 MB
|
Id soluție | #30317658 | Utilizator | |
Fișier | spiralmatrix.cpp | Dimensiune | 1.21 KB |
Data încărcării | 15 Iulie 2021, 14:53 | Scor / rezultat | Eroare de compilare |
spiralmatrix.cpp:6:14: error: expected ']' before numeric constant int n,a[1000 001][1000 001],nr=1,s=1,d=1,u,c,ok=0; ^ spiralmatrix.cpp: In function 'int main()': spiralmatrix.cpp:14:5: error: 'u' was not declared in this scope u=c=n; ^ spiralmatrix.cpp:14:7: error: 'c' was not declared in this scope u=c=n; ^ spiralmatrix.cpp:16:11: error: 'nr' was not declared in this scope while(nr<n*n){ ^ spiralmatrix.cpp:17:29: error: 'ok' was not declared in this scope if(p == (n*n)/2 && ok==0){ ^ spiralmatrix.cpp:18:16: error: 's' was not declared in this scope g<<s<<" "<<d<<endl; ^ spiralmatrix.cpp:18:24: error: 'd' was not declared in this scope g<<s<<" "<<d<<endl; ^ spiralmatrix.cpp:22:13: error: 'ok' was not declared in this scope if(ok==1 && n%2==0 && p==2) ^ spiralmatrix.cpp:23:16: error: 's' was not declared in this scope g<<s<<" "<<d; ^ spiralmatrix.cpp:23:24: error: 'd' was not declared in this scope g<<s<<" "<<d; ^ spiralmatrix.cpp:25:16: error: 's' was not declared in this scope g<<s<<" "<<d; ^ spiralmatrix.cpp:25:24: error: 'd' was not declared in this scope g<<s<<" "<<d; ^ spiralmatrix.cpp:27:12: error: 's' was not declared in this scope if(s==n-c+1 && d<u){ ^ spiralmatrix.cpp:27:24: error: 'd' was not declared in this scope if(s==n-c+1 && d<u){ ^ spiralmatrix.cpp:28:13: error: 'a' was not declared in this scope a[s][d]=nr; ^ spiralmatrix.cpp:33:13: error: 'a' was not declared in this scope a[s][d]=nr; ^ spiralmatrix.cpp:38:13: error: 'a' was not declared in this scope a[s][d]=nr; ^ spiralmatrix.cpp:46:13: error: 'a' was not declared in this scope a[s][d]=nr; ^ spiralmatrix.cpp:56:9: error: 'a' was not declared in this scope a[n/2+1][n/2+1]=n*n; ^ spiralmatrix.cpp:58:9: error: 'a' was not declared in this scope a[n/2+1][n/2]=n*n; ^ spiralmatrix.cpp:12:9: warning: unused variable 'i' [-Wunused-variable] int i=0,j=0; ^ spiralmatrix.cpp:12:13: warning: unused variable 'j' [-Wunused-variable] int i=0,j=0; ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema SpiralMatrix face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.