[模板] 離散化 Discretization
最近看到OTOTOT的離散化模板(雖然現在他的blog鎖住了),所以就心血來潮的也寫了一個XD (有點弱QQ) (第N次校稿@@) (model這個名字也怪怪的@@)
I saw OTOTOT's template of discretization recently, so I make one for myself on a whim. XD
I saw OTOTOT's template of discretization recently, so I make one for myself on a whim. XD
class discretization{ private: vector<int> lisan,status; public: inline vector<int> com(vector<int> a) { status.resize(a.size()); lisan = a; sort(lisan.begin(),lisan.end()); lisan.resize(unique(lisan.begin(),lisan.end())-lisan.begin()); for(int i = 0; i < (int)a.size(); i++) status[i] = lower_bound(lisan.begin(),lisan.end(),a[i])-lisan.begin(); return status; } inline vector<int> model(vector<int> a) { lisan = a; sort(lisan.begin(),lisan.end()); lisan.resize(unique(lisan.begin(),lisan.end())-lisan.begin()); return lisan; } };
留言
張貼留言