蒟蒻目前需要做到浮点数的离散化。
代码如下
struct CMP
{
long double x;
bool operator< (const CMP& a) const
{
return a.x-x>-ERR;
}
bool operator== (const CMP& a) const
{
return abs(a.x-x)<ERR;
}
} t[N*2];
void lsh()
{
for(int i=1; i<=n; i++)
t[i].x=x[i].tl,t[i+n].x=x[i].tr;
std::sort(t+1,t+1+2*n),m=std::unique(t+1,t+1+2*n)-t-1;
for(int i=1; i<=n; i++)
{
CMP l,r;
l.x=x[i].tl,r.x=x[i].tr;
x[i].l=std::lower_bound(t,t+1+m,l)-t,
x[i].r=std::lower_bound(t,t+1+m,r)-t;
}
}
大佬们可以看到对long double即浮点数比较做了特化。
蒟蒻很想知道这份代码有没有可能出错。