0
에 포함하지 않는지도에서 표준 : :지도 요소를 제거? 그런 작업에 가장 적합한 컨테이너입니까?말, 키가 STL 컨테이너 감안할 때 다른 벡터
// Assuming real_objets is sorted (otherwise sort it)
auto first = some_container.begin();
for(int i : real_objects) {
// end of the chunk to erase is the place where i could be
// inserted without breaking the order
auto last = some_container.lower_bound(i);
some_container.erase(first, last);
// if i is a key in the container, skip that element
if(last != some_container.end() && last->first == i) {
++last;
}
first = last;
}
// and in the end, kill stuff that comes after real_objects.back()
some_container.erase(first, some_container.end());
n은 real_objects.size()
및 m은 some_container.size()
이다이 가지고 실행 복잡도가 O (N * 로그 (m)) 의미 :
['std :: remove_if()'] (http://en.cppreference.com/w/cpp/algorithm/remove)와 적절한 람다를 사용하여 구현할 수 있습니다. –
먼저지도의 키와 벡터의 차이점을 설정 한 다음 남은 것을 제거하십시오. – PeterT