离散化

有两种方法,只贴出较为简便的一种 stl 实现离散化 

#include<algorithm> // 头文件 
//n 原数组大小 num 原数组中的元素 lsh 离散化的数组 cnt 离散化后的数组大小  

int lsh[MAXN] , cnt , num[MAXN] , n; for(int i=1; i<=n; i++) { scanf("%d",&num[i]); lsh[i] = num[i]; } sort(lsh+1 , lsh+n+1); cnt = unique(lsh+1 , lsh+n+1) - lsh - 1; for(int i=1; i<=n; i++) num[i] = lower_bound(lsh+1 , lsh+cnt+1 , num[i]) - lsh;
rush!
原文地址:https://www.cnblogs.com/LH2000/p/12372284.html