What is an efficient way to match n items with corresponding n items
This question already has an answer here:
Nice problem but as it was pointed before it seems a Homework, why you don't try something like this:
you should cycle for each bottle (without any logical order) you should have the caps in a kind of structure that is a dynamic sorted array of caps sets, this array is initialized having only one element (that is the set B).
and for each bottle you should travel in your array using Binary Search when you get the "potential" set of caps, you check cap by cap
Edit: i have seen the posted coment and indeed it is duplicate from Two sets of items. Each element of set A a unique match in set B. Match each item of set A to item in set B in O(nlogn) time and the solution is explained here http://www.wisdom.weizmann.ac.il/~naor/PUZZLES/nuts_solution.html
quite similar to mine, but bottles can be partitioned also.
链接地址: http://www.djcxy.com/p/12204.html上一篇: 在PHP中验证信用卡的最佳方式是什么?