#878
Se consideră un șir de n intervale închise întregi. Două intervale consecutive în șir care au intersecția nevidă se reunesc și se înlocuiesc în șir cu intervalul reuniune. Operația se repetă până când nu mai sunt în șir două intervale consecutive cu intersecția nevidă.
Să se determine câte intervale există în șir după realizarea acestor operații.
| Problema | Intervale4 | Operații I/O |
intervale4.in/intervale4.out
|
|---|---|---|---|
| Limita timp | 0.2 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64152935 | Utilizator | |
| Fișier | intervale4.cpp | Dimensiune | 1.11 KB |
| Data încărcării | 20 Aprilie 2026, 18:21 | Scor/rezultat | Eroare de compilare |
intervale4.cpp:3:13: error: variable ‘std::ifstream cin’ has initializer but incomplete type 3 | ifstream cin("intervale4.in"); | ^ intervale4.cpp:4:14: error: variable ‘std::ofstream cout’ has initializer but incomplete type 4 | ofstream cout("intervale4.out"); | ^ intervale4.cpp:14:1: error: expected unqualified-id before ‘{’ token 14 | { | ^ intervale4.cpp:17:1: error: ‘v’ does not name a type 17 | v[1001]; | ^ intervale4.cpp:18:27: error: ‘a’ has incomplete type 18 | bool intersectie(interval a, interval b) | ~~~~~~~~~^ intervale4.cpp:13:8: note: forward declaration of ‘struct interval’ 13 | struct interval; | ^~~~~~~~ intervale4.cpp:18:39: error: ‘b’ has incomplete type 18 | bool intersectie(interval a, interval b) | ~~~~~~~~~^ intervale4.cpp:13:8: note: forward declaration of ‘struct interval’ 13 | struct interval; | ^~~~~~~~ intervale4.cpp: In function ‘bool intersectie(interval, interval)’: intervale4.cpp:20:37: error: expected ‘;’ before ‘}’ token 20 | return !(a.x > b.y || a.y < b.x) | ^ | ; 21 | } | ~ intervale4.cpp: At global scope: intervale4.cpp:22:44: error: ‘x’ has incomplete type 22 | void push(interval v[], int &top, interval x) | ~~~~~~~~~^ intervale4.cpp:13:8: note: forward declaration of ‘struct interval’ 13 | struct interval; | ^~~~~~~~ intervale4.cpp: In function ‘void push(interval*, int&, interval)’: intervale4.cpp:25:10: error: invalid use of incomplete type ‘struct interval’ 25 | v[top]=x; | ^ intervale4.cpp:13:8: note: forward declaration of ‘struct interval’ 13 | struct interval; | ^~~~~~~~ intervale4.cpp: At global scope: intervale4.cpp:27:36: error: return type ‘struct interval’ is incomplete 27 | interval pop(interval v[], int &top) | ^ intervale4.cpp: In function ‘void pop(interval*, int&)’: intervale4.cpp:29:13: error: expected unqualified-id before ‘=’ token 29 | interval=x=v[top]; | ^ intervale4.cpp:31:12: error: ‘x’ was not declared in this scope 31 | return x; | ^ intervale4.cpp: At global scope: intervale4.cpp:33:40: error: return type ‘struct interval’ is incomplete 33 | interval vizitare(interval v[], int top) | ^ intervale4.cpp: In function ‘void vizitare(interval*, int)’: intervale4.cpp:35:18: error: invalid use of incomplete type ‘struct interval’ 35 | return v[top]; | ^ intervale4.cpp:13:8: note: forward declaration of ‘struct interval’ 13 | struct interval; | ^~~~~~~~ intervale4.cpp: At global scope: intervale4.cpp:37:6: error: redefinition of ‘bool stiva_vida(int)’ 37 | bool stiva_vida(int top) | ^~~~~~~~~~ intervale4.cpp:5:6: note: ‘bool stiva_vida(int)’ previously defined here 5 | bool stiva_vida(int top) | ^~~~~~~~~~ intervale4.cpp:41:28: error: ‘a’ has incomplete type 41 | interval reuniune(interval a, interval b) | ~~~~~~~~~^ intervale4.cpp:13:8: note: forward declaration of ‘struct interval’ 13 | struct interval; | ^~~~~~~~ intervale4.cpp:41:40: error: ‘b’ has incomplete type 41 | interval reuniune(interval a, interval b) | ~~~~~~~~~^ intervale4.cpp:13:8: note: forward declaration of ‘struct interval’ 13 | struct interval; | ^~~~~~~~ intervale4.cpp:41:41: error: return type ‘struct interval’ is incomplete 41 | interval reuniune(interval a, interval b) | ^ intervale4.cpp: In function ‘void reuniune(interval, interval)’: intervale4.cpp:43:14: error: aggregate ‘interval r’ has incomplete type and cannot be defined 43 | interval r; | ^ intervale4.cpp: In function ‘int main()’: intervale4.cpp:51:14: error: aggregate ‘interval a’ has incomplete type and cannot be defined 51 | interval a, b; | ^ intervale4.cpp:51:17: error: aggregate ‘interval b’ has incomplete type and cannot be defined 51 | interval a, b; | ^ intervale4.cpp:53:5: error: reference to ‘cin’ is ambiguous 53 | cin >> n; | ^~~ In file included from intervale4.cpp:1: /usr/include/c++/13/iostream:62:18: note: candidates are: ‘std::istream std::cin’ 62 | extern istream cin; ///< Linked to standard input | ^~~ intervale4.cpp:3:10: note: ‘<typeprefixerror>cin’ 3 | ifstream cin("intervale4.in"); | ^~~ intervale4.cpp:56:9: error: reference to ‘cin’ is ambiguous 56 | cin >> a.x >> a.y; | ^~~ /usr/include/c++/13/iostream:62:18: note: candidates are: ‘std::istream std::cin’ 62 | extern istream cin; ///< Linked to standard input | ^~~ intervale4.cpp:3:10: note: ‘<typeprefixerror>cin’ 3 | ifstream cin("intervale4.in"); | ^~~ intervale4.cpp:57:59: error: ‘v’ was not declared in this scope 57 | while(!stiva_vida(top) && intersectie(a, vizitare(v, top))) | ^ intervale4.cpp:62:14: error: ‘v’ was not declared in this scope 62 | push(v, top, a); | ^ intervale4.cpp:64:5: error: reference to ‘cout’ is ambiguous 64 | cout << top+1; | ^~~~ /usr/include/c++/13/iostream:63:18: note: candidates are: ‘std::ostream std::cout’ 63 | extern ostream cout; ///< Linked to standard output | ^~~~ intervale4.cpp:4:10: note: ‘<typeprefixerror>cout’ 4 | ofstream cout("intervale4.out"); | ^~~~
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Intervale4 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ă.