Masalalar:
Task 4. Karobka va sharlar.
Task 5. Katta va kichiklar uchun bilet narxi.
Task 6. Natural sonlarni ikkilik sanoq ko’rinishiga o’tkazib, ular orasida 1 ta nolga ega sonlar.
4-masala c++ da dastur kodi:
#include #include #include #include
while (!all_of(vec.begin(), vec.end(), [](int x){ if (x) return true; }))
{
auto nol = vec.begin();
while (nol != vec.end() && *nol != 0) nol++;
auto it = vec.begin();
int i = -1;
int k = M + 2;
while (it != vec.end())
{
if (it != nol && *it > 1 && k > min(((it - nol) + M) % M, abs(it - nol)))
{
k = min(((it - nol) + M) % M, abs(it - nol));
i = it - vec.begin();
}
it++;
}
K += k;
*nol = *nol + 1;
vec[i]--;
if (debug)
{
cout << hue::green << i + 1 << " " << nol - vec.begin() + 1 << " " << k << hue::reset << endl;
copy(vec.begin(), vec.end(), ostream_iterator(cout, " "));
int p = nol - vec.begin();