85712024-01-22 11:26:24tamasmarkBináris fa magassága (50 pont)cpp17Hibás válasz 21/50143ms94928 KiB
// Binarisfa2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <deque>
#include <cmath>
#include <algorithm>

using namespace std;

struct adat {
    int ertek, hossz=1,sum;
    deque<int>bin;
};
deque<int>binaris;
deque<adat>x;
int a, b,maxi,db,n,m;
void atalakit(int a)
{
    while (a > 0)
    {
        binaris.push_front(a % 2);
        a = a / 2;
    }
}

void melysegi(int csp)
{
    if (csp * 2 + 1 <= pow(2, n) - 1 && csp * 2 <= pow(2, n) - 1)
    {
        x[csp].sum = max(x[csp * 2].sum + x[csp * 2].hossz, x[(csp * 2) + 1].sum + x[(csp * 2) + 1].hossz);
    }
    if (binaris.size() > 1)
    {
        if (binaris.back() == 1)
        {
            binaris.pop_back();
            melysegi((csp - 1) / 2);
        }
        else if (binaris.back() == 0)
        {
            binaris.pop_back();
            melysegi(csp / 2);
        }

    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    x.resize(pow(2, n)); 
    for (int i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].hossz = b;
        atalakit(a);
        maxi = 0;
        melysegi(a);
        binaris.clear();
        cout << x[1].sum << "\n";
    }
    return 0;
}
/*
3 5
2 6
4 3
6 7
5 4
2 1
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base21/50
1Elfogadva0/03ms1832 KiB
2Hibás válasz0/098ms92768 KiB
3Elfogadva2/23ms2244 KiB
4Elfogadva2/23ms2216 KiB
5Elfogadva2/23ms2376 KiB
6Elfogadva2/23ms2576 KiB
7Hibás válasz0/33ms2796 KiB
8Elfogadva3/33ms2796 KiB
9Hibás válasz0/34ms3144 KiB
10Hibás válasz0/33ms3184 KiB
11Elfogadva2/2127ms93828 KiB
12Elfogadva2/2127ms93828 KiB
13Elfogadva2/2143ms94104 KiB
14Elfogadva2/2142ms93916 KiB
15Elfogadva2/2136ms93996 KiB
16Hibás válasz0/2103ms94264 KiB
17Hibás válasz0/2100ms94044 KiB
18Hibás válasz0/2100ms94228 KiB
19Hibás válasz0/2101ms94248 KiB
20Hibás válasz0/3105ms94276 KiB
21Hibás válasz0/3112ms94800 KiB
22Hibás válasz0/3105ms94640 KiB
23Hibás válasz0/3112ms94928 KiB