zoukankan      html  css  js  c++  java
  • 三种离散化

    等有空再测试

    ```cpp

    #define  debug(x) cerr<<#x<<" = "<<x<<endl
    #include <bits/stdc++.h>
    using namespace std;
    const int maxn = 3e5 + 5;
    const int inf = 0x3f3f3f3f;
    int n = 10, m, ans;
    int a[] = {1, 55, 777, 5, 89, 433, 242, 55555555, 242, 777};
    vector<int> hush(a, a + n);
    int b[10], c[10];
    void initHush1() {
        sort(hush.begin(), hush.end());
        auto it = unique(hush.begin(), hush.end());
        hush.resize(distance(hush.begin(), it));
    }
    inline int getId1(int x) {
        return distance(hush.begin(), lower_bound(hush.begin(), hush.end(), x));
    }
    void initHush2() {
        for (int i = 0; i < n; ++i) {
            b[i] = a[i];
        }
        sort(b, b + n);
        m = unique(b, b + n) - b;
    }
    inline int getId2(int x) {
        return lower_bound(b, b + m, x) - b;
    }
    struct Node {
        int val, pos;
        bool operator<(const Node &T) const {
            if (val == T.val)return pos < T.pos;
            return val < T.val;
        }
    } V[10];
    void initHush3() {
        for (int i = 0; i < n; ++i) {
            V[i].val = a[i];
            V[i].pos = i;
        }
        sort(V, V + n);
        for (int i = 1, j = 0; i < n; i++) {
            if (i == 1 || V[i].val != V[i - 1].val)j++;
            c[V[i].pos] = j;
        }
    }
    int getId3(int pos){
        return c[pos];
    }
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        initHush1();
        initHush2();
        initHush3();
        debug(getId1(1));
        debug(getId1(55555));
        debug(getId2(1));
        debug(getId2(55555));
        debug(getId3(1));
        debug(getId3(5));
        return 0;
    }
    /*
    8 5
    1 4
    3 6
    4 5
    4 6
    4 7
    */

    ```

  • 相关阅读:
    一元回归1_基础(python代码实现)
    fisher's exact test
    卡方检验(python代码实现)
    Hough transform(霍夫变换)
    【算法】怎样把一个单链表反序?
    HTTP请求格式和HTTP响应格式
    TCP/IP、SOCKET、HTTP之间的联系与区别
    Graphical vi-vim Cheat Sheet and Tutorial
    Linux远程上传、下载文件的方法
    matlab工作空间,变量的保存和载入
  • 原文地址:https://www.cnblogs.com/tieway59/p/10930681.html
Copyright © 2011-2022 走看看