在线离散化

我们以前遇到需要离散化的题目,大部分都是先对原数组排序,再unique,然后二分,进行离散化。

这里介绍一种在线的离散化方法,那就是利用map

map<int,int> mp;
int Hash(int x)
{
    if(mp.find(x)==mp.end()) mp[x]=tot++;
    return mp[x];
}

猜你喜欢

转载自blog.csdn.net/qq_40774175/article/details/81055088