简体   繁体   中英

C++: Efficient way to check if elements in a vector are greater than elements in another having same indices?

I have a vector < vector <int> > like so:

v = {{1,2,3}, {4,2,1}, {3,1,1}....}}

All v 's elements like v[0] , v[1] , v[2] ... have the same size. There may be duplicate elements.

What I am trying to do is to find and delete vectors (like v[2] ) that are "majorized" by another vector (like v[1] ), ie all elements of v[1] are greater than/equal to the respective elements(in order of indices) in v[2] .

A naive way of doing this would be to loop thorough v and compare each vector with another vector and further compare each element with another vector's element.

But I feel there must a better way to do this without getting O(n^3) in the number of elements of all the vectors in v .

If multiple vectors are equal, I need only one of them (ie delete all except one). A random choice would be sufficient.

Any thoughts or ideas are appreciated!

This is called the maxima of a point set . For two and three dimensions, this can be solved in O(n log n) time. For more than three dimensions, this can be solved in O(n(log n)^(d − 3) log log n) time. For random points, a linear expected time algorithm is available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM