#1425
Ghirlande
Deoarece vin sărbătorile, elevii de la Liceul de informatică s-au gândit să decoreze laboratorul P1
cu ghirlande legate între ele. Ei au cumpărat N
ghirlande numerotate de la 1
la N
și vor să le lege împreună apoi să orneze laboratorul. Fiecare ghirlandă are doua culori distribuite astfel încât capetele să aibă culori diferite. Culorile sunt codificate prin numere naturale. Decoraţiunile cumpărate au N-1
culori care apar exact de două ori şi 2
culori care apar doar o singură dată. Pentru a face munca mai distractivă ei s-au gândit că, la legarea a două ghirlande, să unească două capete de aceeaşi culoare.
1) Pentru cerinţa 1 copiii vor să afle suma codurilor culorilor aflate la cele două capete ale lanţului format prin legarea ghirlandelor cumpărate, respectând regulile de îmbinare de mai sus.
2) Pentru cerinţa 2 ajutaţi-i să lege ghirlandele pentru a decora laboratorul P1 respectând regulile menţionate. Trebuie sa afisati numerele de ordine ale ghirlandelor în ordinea în care vor fi legate. La cele doua capete se vor afla
cele doua ghirlande care conțin o culoare ce apare o singura data. Dintre acestea prima va fi cea care are codul culorii mai mic
Problema | Ghirlande | Operații I/O |
![]() ghirlande.in /ghirlande.out
|
---|---|---|---|
Limita timp | 1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
Id soluție | #55132938 | Utilizator | |
Fișier | ghirlande.cpp | Dimensiune | 2.83 KB |
Data încărcării | 28 Decembrie 2024, 19:57 | Scor / rezultat | Eroare de compilare |
ghirlande.cpp: In function 'int main()': ghirlande.cpp:53:22: error: expected unqualified-id before '[' token auto [nextColor, idx] = entry.second[0]; ^ ghirlande.cpp:54:34: error: 'nextColor' was not declared in this scope start = {color, {nextColor, idx}}; ^ ghirlande.cpp:54:45: error: 'idx' was not declared in this scope start = {color, {nextColor, idx}}; ^ ghirlande.cpp:54:23: error: no match for 'operator=' (operand types are 'std::pair<int, std::pair<int, int> >' and '<brace-enclosed initializer list>') start = {color, {nextColor, idx}}; ^ ghirlande.cpp:54:23: note: candidates are: In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from ghirlande.cpp:1: /usr/include/c++/4.8/bits/stl_pair.h:158:7: note: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_T1, _T2>&) [with _T1 = int; _T2 = std::pair<int, int>] operator=(const pair& __p) ^ /usr/include/c++/4.8/bits/stl_pair.h:158:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::pair<int, std::pair<int, int> >&' /usr/include/c++/4.8/bits/stl_pair.h:166:7: note: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_T1, _T2>&&) [with _T1 = int; _T2 = std::pair<int, int>] operator=(pair&& __p) ^ /usr/include/c++/4.8/bits/stl_pair.h:166:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::pair<int, std::pair<int, int> >&&' /usr/include/c++/4.8/bits/stl_pair.h:177:2: note: template<class _U1, class _U2> std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = std::pair<int, int>] operator=(const pair<_U1, _U2>& __p) ^ /usr/include/c++/4.8/bits/stl_pair.h:177:2: note: template argument deduction/substitution failed: ghirlande.cpp:54:23: note: couldn't deduce template parameter '_U1' start = {color, {nextColor, idx}}; ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from ghirlande.cpp:1: /usr/include/c++/4.8/bits/stl_pair.h:186:2: note: template<class _U1, class _U2> std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = std::pair<int, int>] operator=(pair<_U1, _U2>&& __p) ^ /usr/include/c++/4.8/bits/stl_pair.h:186:2: note: template argument deduction/substitution failed: ghirlande.cpp:54:23: note: couldn't deduce template parameter '_U1' start = {color, {nextColor, idx}}; ^ ghirlande.cpp:71:24: error: expected unqualified-id before '[' token for (auto &[otherColor, idx] : nextList) { ^ ghirlande.cpp:71:24: error: expected ';' before '[' token ghirlande.cpp:71:25: error: 'otherColor' was not declared in this scope for (auto &[otherColor, idx] : nextList) { ^ ghirlande.cpp:71:37: error: 'idx' was not declared in this scope for (auto &[otherColor, idx] : nextList) { ^ ghirlande.cpp: In lambda function: ghirlande.cpp:71:42: error: expected '{' before ':' token for (auto &[otherColor, idx] : nextList) { ^ ghirlande.cpp: In function 'int main()': ghirlande.cpp:71:42: error: expected ';' before ':' token ghirlande.cpp:71:42: error: expected primary-expression before ':' token ghirlande.cpp:71:42: error: expected ')' before ':' token ghirlande.cpp:71:42: error: expected primary-expression before ':' token ghirlande.cpp:71:42: error: expected ';' before ':' token ghirlande.cpp:110:1: error: expected '}' at end of input } ^ ghirlande.cpp:69:19: warning: unused variable 'nextList' [-Wunused-variable] auto &nextList = fr[nextColor]; ^ ghirlande.cpp:70:18: warning: unused variable 'found' [-Wunused-variable] bool found = false; ^ ghirlande.cpp:61:13: warning: unused variable 'currentColor' [-Wunused-variable] int currentColor = start.first; ^ ghirlande.cpp:110:1: error: expected '}' at end of input } ^ ghirlande.cpp:110:1: error: expected '}' at end of input
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Ghirlande 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ă.