#1133
Charlie
Charlie a decis să se joace cu literele dintr-un șir de caractere, șir ce conține doar literele mici ale alfabetului englez ’a’…’z’
. Jocul constă în a elimina litere din șir după următoarea regulă: fie L1
, L2
, L3
trei litere aflate pe poziții consecutive în șir, atunci litera L2
poate fi eliminată dacă și numai dacă este strict mai mică lexicografic decât literele L1
și L3
.
Pentru a face jocul mai interesant, Charlie atașează eliminării literei L2
un cost egal cu valoarea maximă dintre ō(L1)
și ō(L3)
, unde prin ō(litera)
înțelegem numărul de ordine al literei respective în alfabet (ō(’a’)=1
, ō(’b’)=2
,…, ō(’z’)=26
). Charlie aplică în mod repetat procedeul de eliminare și calculează suma costurilor eliminărilor efectuate.
Fiind dat un șir de caractere să se determine:
a) Lungimea maximă a unei secvențe de litere alternante, adică o secvență pentru care literele aflate pe poziții consecutive sunt de forma: L
i
> L
i+1
< L
i+2
> L
i+3
< L
i+4
> … < L
j
.
b) Suma maximă pe care o poate obține Charlie aplicând în mod repetat procedeul de eliminare a literelor, precum și șirul obținut în final.
Problema | Charlie | Operații I/O |
charlie.in /charlie.out
|
---|---|---|---|
Limita timp | 0.5 secunde | Limita memorie |
Total: 4 MB
/
Stivă 2 MB
|
Id soluție | #23796326 | Utilizator | |
Fișier | charlie.cpp | Dimensiune | 2.64 KB |
Data încărcării | 30 August 2020, 22:56 | Scor / rezultat | Eroare de compilare |
charlie.cpp: In function 'void UpdateScore(std::list<charStruct>::iterator)': charlie.cpp:47:42: error: no matching function for call to 'std::multiset<scoreStruct, setSort>::insert(<brace-enclosed initializer list>)' it->sit = scores.insert({ newScore, it }); ^ charlie.cpp:47:42: note: candidates are: In file included from /usr/include/c++/4.8/set:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from charlie.cpp:1: /usr/include/c++/4.8/bits/stl_multiset.h:454:7: note: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::value_type = scoreStruct] insert(const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_multiset.h:454:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const scoreStruct&}' /usr/include/c++/4.8/bits/stl_multiset.h:459:7: note: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::value_type = scoreStruct] insert(value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_multiset.h:459:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::multiset<scoreStruct, setSort>::value_type&& {aka scoreStruct&&}' /usr/include/c++/4.8/bits/stl_multiset.h:484:7: note: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::value_type = scoreStruct] insert(const_iterator __position, const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_multiset.h:484:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_multiset.h:489:7: note: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::value_type = scoreStruct] insert(const_iterator __position, value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_multiset.h:489:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_multiset.h:503:9: note: template<class _InputIterator> void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>] insert(_InputIterator __first, _InputIterator __last) ^ /usr/include/c++/4.8/bits/stl_multiset.h:503:9: note: template argument deduction/substitution failed: charlie.cpp:47:42: note: candidate expects 2 arguments, 1 provided it->sit = scores.insert({ newScore, it }); ^ In file included from /usr/include/c++/4.8/set:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from charlie.cpp:1: /usr/include/c++/4.8/bits/stl_multiset.h:515:7: note: void std::multiset<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>] insert(initializer_list<value_type> __l) ^ /usr/include/c++/4.8/bits/stl_multiset.h:515:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<scoreStruct>' charlie.cpp: In function 'int main()': charlie.cpp:62:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 1; i < input.size();i++) ^ charlie.cpp:64:17: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses] if (input[i] > input[i - 1] == comp) ^ charlie.cpp:74:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] while (i<input.size()&& input[i] > input[i - 1]!=false) ^ charlie.cpp:74:38: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses] while (i<input.size()&& input[i] > input[i - 1]!=false) ^ charlie.cpp:95:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i < input.size(); i++) ^ charlie.cpp:103:42: error: no matching function for call to 'std::multiset<scoreStruct, setSort>::insert(<brace-enclosed initializer list>)' it->sit = scores.insert({newScore,it}); ^ charlie.cpp:103:42: note: candidates are: In file included from /usr/include/c++/4.8/set:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from charlie.cpp:1: /usr/include/c++/4.8/bits/stl_multiset.h:454:7: note: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::value_type = scoreStruct] insert(const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_multiset.h:454:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const scoreStruct&}' /usr/include/c++/4.8/bits/stl_multiset.h:459:7: note: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::value_type = scoreStruct] insert(value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_multiset.h:459:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::multiset<scoreStruct, setSort>::value_type&& {aka scoreStruct&&}' /usr/include/c++/4.8/bits/stl_multiset.h:484:7: note: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::value_type = scoreStruct] insert(const_iterator __position, const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_multiset.h:484:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_multiset.h:489:7: note: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<scoreStruct>; std::multiset<_Key, _Compare, _Alloc>::value_type = scoreStruct] insert(const_iterator __position, value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_multiset.h:489:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_multiset.h:503:9: note: template<class _InputIterator> void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>] insert(_InputIterator __first, _InputIterator __last) ^ /usr/include/c++/4.8/bits/stl_multiset.h:503:9: note: template argument deduction/substitution failed: charlie.cpp:103:42: note: candidate expects 2 arguments, 1 provided it->sit = scores.insert({newScore,it}); ^ In file included from /usr/include/c++/4.8/set:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from charlie.cpp:1: /usr/include/c++/4.8/bits/stl_multiset.h:515:7: note: void std::multiset<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = scoreStruct; _Compare = setSort; _Alloc = std::allocator<scoreStruct>] insert(initializer_list<value_type> __l) ^ /usr/include/c++/4.8/bits/stl_multiset.h:515:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<scoreStruct>'
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Charlie 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ă.