Вітаю Вас, Гість

Задача А.

#include <iostream>

using namespace std;

int a[255];

int main()

{   int n; char c;

     cin >> n;

     for (int i=0; i<n; ++i)

     {

         cin >> c;

         a[c]++;

     }

    cout << n-max(a['a'],max(a['b'],a['c']));

    return 0;

}

 

Задача В.

#include <iostream>

#include <cstdio>

#include <string>

using namespace std;

int main()

{

    long a=0,x,sum;

     string s;

    cin>>s;

    while (s.length()>1)

        {a++;

         sum=0;

         for (int i=0;i<s.length();i++) sum+=(s[i]-'0');

        s="";

        while (sum>0)

        {   char c=sum%10+'0';

            s = s+c;

            sum=sum/10;

        }

        }

    cout << a << endl;

    return 0;

}

 

Задача С.

#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

vector<size_t> leftDeck, rightDeck;

void shuffle(vector<size_t>& vec) {
    leftDeck.resize(0);
    rightDeck.resize(0);

    bool putToRight = true;
    for (size_t i = vec.size() - 1; i != -1; --i) {
        if (putToRight) {
            rightDeck.push_back(vec[i]);
        } else {
            leftDeck.push_back(vec[i]);
        }
        putToRight = !putToRight;
    }

    vec.resize(0);
    for (size_t i = 0; i < rightDeck.size(); ++i) vec.push_back(rightDeck[i]);
    for (size_t i = 0; i < leftDeck.size(); ++i) vec.push_back(leftDeck[i]);
}

int main() {
    size_t n;
    unsigned long long k;
    cin >> n >> k;
    vector<size_t> cartDeck(n);
    for (size_t i = 0; i < n; ++i) cartDeck[i] = i;
    size_t cTrys = 0;

    while (true) {
        ++cTrys;
        shuffle(cartDeck);

        bool didLoop = true;
        for (size_t i = 0; i < n; ++i) {
            if (cartDeck[i] != i) {
                didLoop = false;
                break;
            }
        }
        if (didLoop) break;
    }

    for (size_t i = 0; i < n; ++i) cin >> cartDeck[i];

    k %= cTrys;
    for (size_t i = 0; i < k; ++i) shuffle(cartDeck);

    for (size_t i = 0; i < n; ++i) {
        cout << cartDeck[i] << endl;
    }

    return 0;
}

 

Задача D.

#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int k;
    size_t lastSumSmallerK = 4, i = 0;
    cin >> k;

    vector<int> fib(2);
    bool isLastInfinite = false;
    fib[0] = 1; fib[1] = 1;

    while (lastSumSmallerK >= i)
    {
        if (fib[i] + fib[i + 1] <= k) {
            lastSumSmallerK = fib.size();
            isLastInfinite = false;
        } else {
            if (isLastInfinite) {
                fib.pop_back();
                fib.pop_back();
            } else {
                isLastInfinite = true;
            }
        }

        fib.push_back(fib[i] + fib[i + 1]);
        fib.push_back(fib[i + 1]);
        ++i;
    }

    for (size_t i = 0; i < fib.size() - 1; ++i) {
        if (fib[i] <= k && fib[i + 1] <= k) {
            cout << fib[i] << "/" << fib[i + 1] << " ";
        }
    }

    return 0;
}

 

Задача Е.


#include <bits/stdc++.h>

using namespace std;

struct BasicBlock
{
    size_t width, height;
    vector<pair<size_t, size_t>> points;
    vector<size_t> maxHeight;
    vector<size_t> minHeight;
};

char city[3005][3005];
size_t height[3005];

int main()
{
    ios::sync_with_stdio(false);

    vector<BasicBlock> basicBlocks;
    string cleaner;
    size_t n, k, mapWidth, mapHeight;
    memset(city, '.', sizeof(city));
    memset(height, 0, sizeof(height));

    cin >> mapWidth >> mapHeight >> k;

    for (size_t i = 0; i < k; ++i)
    {
        size_t w, h;
        cin >> w >> h;

        BasicBlock block;
        block.width = w;
        block.height = h;
        block.maxHeight.resize(w);
        block.minHeight.resize(w, 30000);

        for (size_t yPos = h - 1; yPos != -1; --yPos)
        {
            for (size_t xPos = 0; xPos < w; ++xPos)
            {
                char c;
                cin >> c;
                if (c == '#')
                {
                    if (yPos < block.minHeight[xPos]) block.minHeight[xPos] = yPos;
                    if (yPos > block.maxHeight[xPos]) block.maxHeight[xPos] = yPos;
                    block.points.push_back(make_pair(xPos, yPos));
                }
            }
        }

        basicBlocks.push_back(block);
    }

    cin >> n;

    for (size_t i = 0; i < n; ++i)
    {
        size_t blockIdx, xPos1, xPos2, yOff = 0;
        cin >> blockIdx >> xPos1 >> xPos2;
        --blockIdx;
        if (xPos2 - xPos1 + 1 != basicBlocks[blockIdx].width)
        {
            clog << "Invalid block-drop #" << i << "(" << blockIdx << " " << xPos1 << " " << xPos2 << "). Expecting width of " << basicBlocks[blockIdx].width << endl;
            throw runtime_error("Width doesn't match basicBlock's width");
        }

        for (size_t xPos = xPos1; xPos <= xPos2; ++xPos)
        {
            if (height[xPos] > basicBlocks[blockIdx].minHeight[xPos - xPos1] &&
                height[xPos] - basicBlocks[blockIdx].minHeight[xPos - xPos1] > yOff)
            {
                yOff = height[xPos] - basicBlocks[blockIdx].minHeight[xPos - xPos1];
            }
        }

        for (size_t xPos = xPos1; xPos <= xPos2; ++xPos)
        {
            height[xPos] = basicBlocks[blockIdx].maxHeight[xPos - xPos1] + yOff + 1;
        }

        for (size_t j = 0; j < basicBlocks[blockIdx].points.size(); ++j)
        {
            city
                [xPos1 + basicBlocks[blockIdx].points[j].first - 1]
                [yOff + basicBlocks[blockIdx].points[j].second] = '#';
        }
    }

    for (size_t i = mapHeight - 1; i != -1; --i)
    {
        for (size_t j = 0; j < mapWidth; ++j)
        {
            cout << city[j][i];
        }
        cout << endl;
    }

    return 0;
}