84962024-01-19 10:55:11tamasmarkBináris fa magassága (50 pont)cpp17Időlimit túllépés 20/50603ms48748 KiB
// Binarisfa2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

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

using namespace std;

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

void melysegi(int csp)
{
    //db += x[csp].hossz;
    /*if (binaris.back() == 0 && binaris.size()>1)
    {
        binaris.pop_back();
        melysegi(csp / 2);
    }
    else if (binaris.back() == 1&&binaris.size()>1)
    {
        binaris.pop_back();
        melysegi((csp - 1) / 2);
    }*/
    a = csp;
    for (auto& e : x[csp].bin)
    {
        if (e == 1)
        {
            
            db += x[a].hossz;
            a = (a - 1) / 2;
        }
        else if (e == 0)
        {
            
            db += x[a].hossz;
            a = a / 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 j = pow(2, n - 1); j <= pow(2, n) - 1; ++j)
    {
        b = j;
        atalakit(j);
    }

    for (int i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].hossz = b;
        maxi = 0;
        for (int j = pow(2, n - 1); j <= pow(2, n) - 1; ++j)
        {
            db= -1;
            melysegi(j);
            if (maxi < db) maxi = db;
        }

        cout << maxi << "\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
base20/50
1Elfogadva0/03ms1704 KiB
2Időlimit túllépés0/0603ms46076 KiB
3Elfogadva2/23ms2092 KiB
4Elfogadva2/23ms2316 KiB
5Elfogadva2/24ms2700 KiB
6Elfogadva2/23ms2756 KiB
7Elfogadva3/34ms3124 KiB
8Elfogadva3/38ms3120 KiB
9Elfogadva3/314ms3476 KiB
10Elfogadva3/314ms3744 KiB
11Időlimit túllépés0/2558ms47644 KiB
12Időlimit túllépés0/2569ms47812 KiB
13Időlimit túllépés0/2564ms47748 KiB
14Időlimit túllépés0/2556ms47664 KiB
15Időlimit túllépés0/2561ms47984 KiB
16Időlimit túllépés0/2546ms47980 KiB
17Időlimit túllépés0/2550ms48056 KiB
18Időlimit túllépés0/2574ms48344 KiB
19Időlimit túllépés0/2550ms48300 KiB
20Időlimit túllépés0/3569ms48508 KiB
21Időlimit túllépés0/3569ms48452 KiB
22Időlimit túllépés0/3554ms48364 KiB
23Időlimit túllépés0/3555ms48748 KiB