в c ++ std :: set , если вы хотите найти наименьшее значение, которое больше или равное x, вам просто нужно вызвать простую функцию Lower_bound/opper_bound в O (log n).
Код: Выделить всё
std::set container = {1, 10, 30};
std::set ::iterator it = container.lower_bound(5); //pointer to the least value >= 5, null if there isn't any
std::cout 2 * x));
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 100; i > 0; --i) {
int a = GetMinRange(ss, ss.Min + i % 10, ss.Max);
int b = GetMaxRange(ss, ss.Min + i % 10, ss.Max);
}
stopwatch.Stop();
Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
}
}
< /code>
Time elapsed: 00:00:13.1506279
< /code>
I want to know if there is another function that performs almost as fast as std::set::lower_bound()
Подробнее здесь: https://stackoverflow.com/questions/797 ... n-a-set-in