#1220
Scadere
Fie n
un număr natural nenul.
Să considerăm o expresie de forma: x[1]-x[2]-x[3]-...-x[n]
Se ştie că scăderea nu este o operaţie asociativă, adică x[1]-(x[2]-x[3])≠(x[1]-x[2])-x[3]
.
Ca urmare, prin plasarea unor perechi de paranteze în expresie, putem obţine diferite valori.
Pentru problema noastră, vom denumi scădere o expresie de forma de mai sus în care pot apărea şi paranteze rotunde care se închid corect. Valoarea unei scăderi se obţine efectuând operaţiile de scădere în ordine de la stânga la dreapta; dacă apar paranteze, se efectuează mai întâi operaţiile din paranteze.
Date fiind valorile x[1]
, x[2]
, …, x[n]
care intervin în scădere, scrieţi un program care să rezolve următoarele două cerinţe:
x[1]-x[2]-x[3]-...-x[n]
), precum şi o scădere având valoare maximă.ONI GIM 2015, Clasa a VII-a
Problema | Scadere | Operații I/O |
![]() scadere.in /scadere.out
|
---|---|---|---|
Limita timp | 0.1 secunde | Limita memorie |
Total: 2 MB
/
Stivă 1 MB
|
Id soluție | #50495348 | Utilizator | |
Fișier | scadere.cpp | Dimensiune | 1.17 KB |
Data încărcării | 11 Aprilie 2024, 16:06 | Scor / rezultat | Eroare de compilare |
scadere.cpp: In function 'int main()': scadere.cpp:33:28: warning: overflow in implicit constant conversion [-Woverflow] dpmax[inc][sf] = INT_MIN; ^ scadere.cpp:34:28: warning: overflow in implicit constant conversion [-Woverflow] dpmin[inc][sf] = INT_MAX; ^ scadere.cpp:37:84: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<short int> >::value_type&, int)' dpmax[inc][sf] = max(dpmax[inc][sf], dpmax[inc][k] - dpmin[k+1][sf]); ^ scadere.cpp:37:84: note: candidates are: In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0, 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 scadere.cpp:1: /usr/include/c++/4.8/bits/stl_algobase.h:216:5: note: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&) max(const _Tp& __a, const _Tp& __b) ^ /usr/include/c++/4.8/bits/stl_algobase.h:216:5: note: template argument deduction/substitution failed: scadere.cpp:37:84: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int') dpmax[inc][sf] = max(dpmax[inc][sf], dpmax[inc][k] - dpmin[k+1][sf]); ^ In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0, 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 scadere.cpp:1: /usr/include/c++/4.8/bits/stl_algobase.h:260:5: note: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare) max(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ /usr/include/c++/4.8/bits/stl_algobase.h:260:5: note: template argument deduction/substitution failed: scadere.cpp:37:84: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int') dpmax[inc][sf] = max(dpmax[inc][sf], dpmax[inc][k] - dpmin[k+1][sf]); ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from scadere.cpp:3: /usr/include/c++/4.8/bits/stl_algo.h:4231:5: note: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>) max(initializer_list<_Tp> __l) ^ /usr/include/c++/4.8/bits/stl_algo.h:4231:5: note: template argument deduction/substitution failed: scadere.cpp:37:84: note: mismatched types 'std::initializer_list<_Tp>' and 'short int' dpmax[inc][sf] = max(dpmax[inc][sf], dpmax[inc][k] - dpmin[k+1][sf]); ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from scadere.cpp:3: /usr/include/c++/4.8/bits/stl_algo.h:4236:5: note: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare) max(initializer_list<_Tp> __l, _Compare __comp) ^ /usr/include/c++/4.8/bits/stl_algo.h:4236:5: note: template argument deduction/substitution failed: scadere.cpp:37:84: note: mismatched types 'std::initializer_list<_Tp>' and 'short int' dpmax[inc][sf] = max(dpmax[inc][sf], dpmax[inc][k] - dpmin[k+1][sf]); ^ scadere.cpp:38:84: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<short int> >::value_type&, int)' dpmin[inc][sf] = min(dpmin[inc][sf], dpmin[inc][k] - dpmax[k+1][sf]); ^ scadere.cpp:38:84: note: candidates are: In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0, 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 scadere.cpp:1: /usr/include/c++/4.8/bits/stl_algobase.h:193:5: note: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&) min(const _Tp& __a, const _Tp& __b) ^ /usr/include/c++/4.8/bits/stl_algobase.h:193:5: note: template argument deduction/substitution failed: scadere.cpp:38:84: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int') dpmin[inc][sf] = min(dpmin[inc][sf], dpmin[inc][k] - dpmax[k+1][sf]); ^ In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0, 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 scadere.cpp:1: /usr/include/c++/4.8/bits/stl_algobase.h:239:5: note: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare) min(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ /usr/include/c++/4.8/bits/stl_algobase.h:239:5: note: template argument deduction/substitution failed: scadere.cpp:38:84: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int') dpmin[inc][sf] = min(dpmin[inc][sf], dpmin[inc][k] - dpmax[k+1][sf]); ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from scadere.cpp:3: /usr/include/c++/4.8/bits/stl_algo.h:4221:5: note: template<class _Tp> _Tp std::min(std::initializer_list<_Tp>) min(initializer_list<_Tp> __l) ^ /usr/include/c++/4.8/bits/stl_algo.h:4221:5: note: template argument deduction/substitution failed: scadere.cpp:38:84: note: mismatched types 'std::initializer_list<_Tp>' and 'short int' dpmin[inc][sf] = min(dpmin[inc][sf], dpmin[inc][k] - dpmax[k+1][sf]); ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from scadere.cpp:3: /usr/include/c++/4.8/bits/stl_algo.h:4226:5: note: template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare) min(initializer_list<_Tp> __l, _Compare __comp) ^ /usr/include/c++/4.8/bits/stl_algo.h:4226:5: note: template argument deduction/substitution failed: scadere.cpp:38:84: note: mismatched types 'std::initializer_list<_Tp>' and 'short int' dpmin[inc][sf] = min(dpmin[inc][sf], dpmin[inc][k] - dpmax[k+1][sf]); ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Scadere 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ă.