离散化及相关操作

2018-07-11 21:00:51


# include <vector>
# include <algorithm>

using namespace std;

vector<int> a;
// 0.. num-1

int x;
a.push_back(x);

sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());

for (int i=1; i<=n; ++i) 
    s[i] = lower_bound(a.begin(), a.end(), s[i]) - a.begin() + 1;

1 2 2 3 3

1 2 3
vector<int> a;
int x;
a.push_back(x);
sort(a.begin(),a.end());
a.erase(unique(a.begin(),a.end()),a.end());
    for(int i=1;i<=n;i++)
    s[i]=lower_bound(a.begin(),a.end(),s[i])-a.begin()+1;