There is a black-and-white picture - some kind of flat figure filled in with black on a white background.
I create an image of the same size, where randomly located points attack only where the original is black.
I do this clearly not optimally: I choose a random point of the original image, and I see what color it is in the original - if black (or яркость < X ), then this point suits me and in these coordinates I put a dot in these coordinates (in fact, I place the sprite ).
How can you optimize / speed up the process so that there are no idle shots, of which most are usually, because the figure has an area much smaller than the whole field).
O(K*N/M), the second algorithm:O(K+N). IfK==1, then obviously the first algorithm is more preferable. IfK~N, then the second algorithm is better for large N, ifM<<N- jfs