I have a home problem that I can only solve in O(max(F)*N)( Nabout 10^5and Fis 10^9) difficulty, and I hope you could help me. I have been given Nsets of 4 integernumbers (called S, F, aand b); Each set of 4 numbers describes a set of numbers as follows: The first includes the following numbers, starting with S. The following bserial numbers are not, then the following numbers arepeat this until you reach the upper limit F. For example, for a S=5;F=50;a=1;b=19set contains a (5,25,45); S=1;F=10;a=2;b=1set contains(1,2,4,5,7,8,10);
I need to find an integer that is contained in an odd number of sets. It is guaranteed that for this test there is ONLY 1 number that complies with this condition.
I tried to go through each number between min(S)and max(F)and check how many sets are included in this number, and if it is included in an odd number of sets, then this is the answer. As I said, this way I get O (F*N)that too much, and I have no other idea how I can find out if a number is in an odd number of sets.
If you could help me, I would be very grateful. Thanks in advance and sorry for my poor english and explanation!
source
share