數據離散化

離散化思想

將已知數值進行排序,從而獲取每個數值在已知數值中的地位。

數值離散化

struct Discretization
{
    vector<int> mp;
    int len;
    void clear(){mp.clear();len=0;}
    void add(int val){mp.push_back(val);}
    void discrete()
    {
        sort(mp.begin(),mp.end());
        mp.resize(unique(mp.begin(),mp.end())-mp.begin());
        len=mp.size();
    }
    int getPos(int val)
    {
        int pos=lower_bound(mp.begin(),mp.end(),val)-mp.begin();
        if(pos==len)return -1;
        else return pos;
    }
    int operator[](int pos){return mp[pos];}
}disc;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章