zoukankan      html  css  js  c++  java
  • L2-012 关于堆的判断 (25 分)

    就是一个最小根堆。

    最小根堆的性质,根节点小于等于子树的完全二叉树吧。

    构建最小根堆的过程就是一个自下向上的过程。

    #include<iostream>
    #include<string>
    #include<map>
    using namespace std;
    
    const int maxn = 10010;
    const int inf = 999999;
    int a[maxn], cnt;
    void creat(int x){
        a[++cnt] = x;
        int t = cnt;
        while (t > 1 && (a[t / 2] > a[t])){
            swap(a[t], a[t / 2]);    t /= 2;
        }
        a[t] = x;
    }
    
    int n, m, x, y;
    string s;
    map<int, int>p;
    
    int main(){
        cin >> n >> m;
        for (int i = 1; i <= n; ++i){ cin >> x; creat(x); }
        for (int i = 1; i <= n; ++i){ p[a[i]] = i; }
        for (int i = 0; i < m; ++i){
            cin >> x;
            cin >> s;
            if (s[0] == 'a'){
                cin >> y >> s >> s;
                if (p[x] / 2 == p[y] / 2)cout << "T" << endl;
                else cout << "F" << endl;
            }
            else{
                cin >> s;
                cin >> s;
                if (s[0] == 'r')
                { if (p[x] == 1)cout << "T" << endl; else cout << "F" << endl; }
                else if (s[0] == 'p')
                {
                    cin >> s; cin >> y; if (p[x] == p[y] / 2)cout << "T" << endl; else cout << "F" << endl;
                }
                else if (s[0] == 'c')
                {
                    cin >> s; cin >> y; if (p[x] / 2 == p[y])cout << "T" << endl; else cout << "F" << endl;
                }
            }
        }
    }
  • 相关阅读:
    Qt 去除控件边框线
    Qt 自定义可编辑 模型视图
    Qt double类型输出问题
    vue实例
    初识vue
    python中的数据类型
    python 列表解析式
    Goland常用快键键 mac pro
    文档对象模型DOM
    正则表达式
  • 原文地址:https://www.cnblogs.com/ALINGMAOMAO/p/10604360.html
Copyright © 2011-2022 走看看