Given n pairs of coordinates, how would you apply coordinate compression if the x and y coordinates don’t have to be distinct?
1 Like
Here’s an easy way to do it (in the 1D case):
#include <iostream>
#include <vector>
#include <map>
int main() {
std::map<int,int> m;
std::vector<int> vals{4,4,2,-1,3,-1,-1};
for (int v: vals) m[v];
int label = 0; for (auto& p: m) p.second = label++;
for (int& v: vals) v = m[v];
for (int v: vals) std::cout << v << " ";
} // 3 3 1 0 2 0 0