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
    */

    ```

  • 相关阅读:
    CSS中expression使用简介
    过滤Html标签代码
    ASP.NET上传图片时显示预览
    30分钟搞定.net正则表达式
    DataFormatString格式化
    Js事件大全
    Hibernate关联映射
    动态给下拉框添加选项
    python模块整理文章导航
    python学习笔记文章导航
  • 原文地址:https://www.cnblogs.com/tieway59/p/10930681.html
Copyright © 2011-2022 走看看