#2202
extindere
Se consideră operația
: {1; 2} → {1; 2}
, astfel încât 1
= 2
, 2
= 1
. Operația se extinde asupra oricărei secvențe formate cu cifre de 1
și 2
, de exemplu 1211212121
=2122121212
.
Se consideră șirul infinit s
format cu cifre de 1
și 2
, generat incremental prin extindere după următoarea regulă de concatenare:
s1 = 1221
, s2 = 1221211221121221
, … , sk+1 = sk
sk sk
sk
, …, pentru orice număr natural nenul k
.
Să se scrie un program care pentru un n
număr natural nenul cunoscut determină și afișează a n
-a cifră a șirului s
, astfel încât numărul de pași ai programului să fie proporțional cu log2(n)
(complexitate timp logaritmică în funcție de n
).
Admitere FMI Bucuresti - 2014
Problema | extindere | Operații I/O |
extindere.in /extindere.out
|
---|---|---|---|
Limita timp | 0.01 secunde | Limita memorie |
Total: 0.1 MB
/
Stivă 0.1 MB
|
Id soluție | #15201866 | Utilizator | |
Fișier | extindere.c | Dimensiune | 726 B |
Data încărcării | 04 Aprilie 2019, 12:49 | Scor / rezultat | Eroare de compilare |
extindere.c: In function 'main': extindere.c:20:5: error: too few arguments to function 'fopen' fp = fopen("extindere.in"); ^ In file included from extindere.c:2:0: /usr/include/stdio.h:272:14: note: declared here extern FILE *fopen (const char *__restrict __filename, ^ extindere.c:21:5: warning: format '%lld' expects argument of type 'long long int *', but argument 3 has type 'long long int' [-Wformat=] fscanf(fp, "%lld", n); ^ extindere.c:33:11: error: redeclaration of 'fp' with no linkage FILE *fp; ^ extindere.c:19:11: note: previous declaration of 'fp' was here FILE *fp; ^ extindere.c:34:5: error: too few arguments to function 'fopen' fp = fopen("extindere.out"); ^ In file included from extindere.c:2:0: /usr/include/stdio.h:272:14: note: declared here extern FILE *fopen (const char *__restrict __filename, ^ extindere.c:37:9: warning: passing argument 1 of 'fprintf' from incompatible pointer type [enabled by default] fprintf("%d", FLIP(init[n - 1])); ^ In file included from /usr/include/stdio.h:937:0, from extindere.c:2: /usr/include/i386-linux-gnu/bits/stdio2.h:95:1: note: expected 'struct FILE * __restrict__' but argument is of type 'char *' fprintf (FILE *__restrict __stream, const char *__restrict __fmt, ...) ^ extindere.c:37:9: warning: passing argument 2 of 'fprintf' makes pointer from integer without a cast [enabled by default] fprintf("%d", FLIP(init[n - 1])); ^ In file included from /usr/include/stdio.h:937:0, from extindere.c:2: /usr/include/i386-linux-gnu/bits/stdio2.h:95:1: note: expected 'const char * __restrict__' but argument is of type 'int' fprintf (FILE *__restrict __stream, const char *__restrict __fmt, ...) ^ extindere.c:37:9: warning: format not a string literal and no format arguments [-Wformat-security] fprintf("%d", FLIP(init[n - 1])); ^ extindere.c:39:9: warning: passing argument 1 of 'fprintf' from incompatible pointer type [enabled by default] fprintf("%d", init[n - 1]); ^ In file included from /usr/include/stdio.h:937:0, from extindere.c:2: /usr/include/i386-linux-gnu/bits/stdio2.h:95:1: note: expected 'struct FILE * __restrict__' but argument is of type 'char *' fprintf (FILE *__restrict __stream, const char *__restrict __fmt, ...) ^ extindere.c:39:9: warning: passing argument 2 of 'fprintf' makes pointer from integer without a cast [enabled by default] fprintf("%d", init[n - 1]); ^ In file included from /usr/include/stdio.h:937:0, from extindere.c:2: /usr/include/i386-linux-gnu/bits/stdio2.h:95:1: note: expected 'const char * __restrict__' but argument is of type 'int' fprintf (FILE *__restrict __stream, const char *__restrict __fmt, ...) ^ extindere.c:39:9: warning: format not a string literal and no format arguments [-Wformat-security] fprintf("%d", init[n - 1]); ^ extindere.c:33:11: warning: variable 'fp' set but not used [-Wunused-but-set-variable] FILE *fp; ^ extindere.c:21:11: warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result] fscanf(fp, "%lld", n); ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema extindere 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ă.