# 离散化

离散化

sort(t,t+n);
int m=unique(t,t+n)-t;//得到去重之后的元素个数

for(int i=0;i<n;i++){
    a[i]=upper_bound(t,t+m,a[i])-t;
}
//离散化后的值从0开始
//a[i]为离散化后**原数组**对应的值
//t[]为排序后的顺序
//t[a[i]]为原数组对应的值

猜你喜欢

转载自www.cnblogs.com/sstealer/p/11209065.html