从一堆较大的集合生成较小集合的算法,因此较小集合上的每一对都是唯一的

时间:2015-09-03 16:20:14

标签: algorithm set

我有大约40组数字,例如:

 setId | numbers
 20048 | 5589,5659,5867,5871,10576,10577,10578,10579,10580,10581,10582,10583,10584,10585,10586,10587,10588,10589,10590,10591,10592,10593,10594,10595,10596,10597,10598,10599,10600,10601,10602,10603,10604,10605,10606,10607,10608,10609,10610,10611,10612,10613,10614
 20102 | 3987,4075,4095,4098,4321,4331,4341,4342,4343,4348,4356,4359,4361,4362,4381,4549,4550,4558,4574,5442,5485,5490,5574,5613,5667,5678,5686,5716,5758,5764,5786,5792,5797,5832,5846,5883,5985,6029,6039,6041,6073,6093,6094,6097,6101,6112,6130,6173,6176,6216,6446,6451,6986,7098,7139,7251,7333,7399,7405,7510,7513,7546,7548,7607,7705,8050,8076,8078
 20117 | 4200,4219,5437,5438,5471,5477,5522,5528,5545,5551,5552,5570,5578,5586,5587,5590,5601,5616,5621,5673,5725,5749,5759,5763,5773,5774,5808,5820,5825,5839,5901,5923,5955,5957,5997,5999,6006,6022,6086,6095,6098,6113,6135,6178,6180,6181,6183,6184,6185,6188,6190,6191,6192,6198,6199,6200,6201,6203,6206,6354,6387
 20178 | 4660,4677,9732,9733,9735,9737,9738,9739,9741,9742,9743,9744,9748,9750,9751,9820,10059,10063,10067,10071,10072,10074,10075,10081,10082,10083,10084,10090,10095,10100,10105,10113,10115,10123,10189,10278,10281,10290
 20231 | 3890,4169,5436,5474,5542,5543,5546,5567,5600,5612,5636,5653,5661,5663,5687,5689,5712,5741,5753,5793,5815,5819,5834,5907,5912,5930,5933,5963,5975,5991,6026,6055,6075,6076,6082,6111,6133,6136,6156,6157,6159,6160,6165,6169,6283,6378,6379,6425
 20232 | 5222,5454,5478,5479,5499,5526,5532,5544,5575,5600,5602,5675,5692,5699,5702,5706,5708,5760,5800,5875,5958,6015,6043,6064,6066,6074,6161,6163,6285,6393,6394,6395,11154,11155,11156,11157,11158,11159,11160,11161,11162,11163,11164,11165,11166,11167,11168,11169,11170,11171,11172,11173,11174,11175,11176,11177,11178,11179,11180,11181,11182,11183,11184,11185,11186,11187,11188,11189,11190
 20233 | 5473,5483,5507,5536,5591,5603,5604,5622,5633,5643,5648,5682,5688,5693,5696,5704,5707,5720,5735,5737,5738,5762,5766,5782,5785,5790,5794,5800,5802,5818,5823,5830,5853,5861,5866,5873,5877,5887,5893,5929,5940,5954,5968,5983,5986,6013,6038,6069,6078,6088,6102,6121,6131,6132,6154,6162,6164,6166,6167,6171,6214,6286,6356,6381,6390
 20236 | 1369,10663,10664,10665,10666,10667,10668,10669,10670,10671,10672,10673,10674,10675,10676,10677,10678,10679,10680,10681,10682,10683,10684,10685,10686,10687,10688,10689,10690,10691,10692,10693,10694,10695,10696,10697,10698,10699,10700,10701,10702,10703,11118,11119,11120,11121,11122,11123,11124,11125,11126,11127,11128,11129,11130,11131,11132,11133,11134,11135,11136,11137,11138,11139,11140,11141,11142,11143,11144,11145,11146,11147,11148,11149,11150,11151,11152,11153
 20237 | 6428,6939,6958,7028,7051,7074,7087,7105,7108,7138,7158,7183,7197,7198,7212,7214,7247,7267,7278,7299,7307,7310,7392,7408,7427,7442,7578,7625,7632,7729,7818,8060,11118,11119,11120,11121,11122,11123,11124,11125,11126,11127,11128,11129,11130,11131,11132,11133,11134,11135,11136,11137,11138,11139,11140,11141,11142,11143,11144,11145,11146,11147,11148,11149,11150,11151,11152,11153
 20240 | 5222,11154,11155,11156,11157,11158,11159,11160,11161,11162,11163,11164,11165,11166,11167,11168,11169,11170,11171,11172,11173,11174,11175,11176,11177,11178,11179,11180,11181,11182,11183,11184,11185,11186,11187,11188,11189,11190
 20257 | 8100,8130,9736,9808,9817,9819,9826,9828,9829,9835,9837,9838,9839,9841,9842,9843,9844,9845,9846,9847,9848,9849,9850,9852,9854,9855,9856,9857,9858,9860,9863,9864,9865,9866,9867,9868,9869,9870,9872,9873,9875,9876,9985,10136,10252,10260,10277
 20259 | 7856,8092,9736,9808,9817,9819,9826,9828,9829,9832,9835,9837,9838,9839,9841,9842,9843,9844,9845,9846,9847,9848,9849,9850,9852,9854,9855,9856,9858,9860,9863,9864,9865,9866,9867,9868,9869,9870,9872,9873,9875,9876,9985,10136,10252,10260,10277
 20261 | 8130,8135,9736,9808,9817,9819,9826,9835,9837,9838,9839,9841,9842,9843,9844,9846,9847,9848,9849,9850,9852,9854,9855,9856,9858,9860,9863,9864,9866,9867,9868,9869,9870,9872,9873,9985,10136,10160,10162,10163,10164,10165,10166,10167,10252,10260,10277
 20262 | 4955,7516,8113,8132,8133,9828,9829,9832,9845,9865,9875,9876
 20349 | 9859,10169,10172,10174,10177,10178,10179,10180,10181,10182,10185,10191,10194,10199,10202,10205,10206,10209,10214,10216,10218,10221,10222,10223,10227,10232,10234,10243,10244,10245,10248,10249,10251,10257,10258,10297
 20350 | 9755,9871,9874,10077,10171,10175,10176,10187,10193,10198,10201,10211,10224,10226,10228,10229,10230,10231,10236,10238,10242,10247,10253,10255,10259,10263,10264,10265,10266,10267,10269,10271,10276,10291,10292,10293
 20396 | 5043,6587,6589,6592,6593,6597,6601,6772,6779,6785,6786,6900,6925,6926,7886,8107,9729,9759,10038,10045,10298
 20397 | 4764,5116,6420,6576,6578,6579,6580,6582,6583,6585,6590,6595,6598,6599,6604,6605,6607,6608,6776,6777,6780,6783,6878,6879,6880,6882,7889,7964,9752,9760,9770,9783
 20398 | 5116,6443,6587,6589,6592,6593,6597,6601,6772,6779,6785,6786,6900,6925,6926,7886,8107,8129,9729,10038,10055
 20399 | 3238,4905,6576,6578,6579,6580,6582,6583,6585,6590,6595,6598,6599,6604,6605,6607,6608,6776,6777,6780,6783,6878,6879,6880,6882,7889,7901,7964,9759,9770,9783
 20413 | 9753,9756,9757,9758,9759,9762,9763,9766,9767,9768,9769,9772,9773,9774,9775,9776,9777,9778,9779,9780,9781,9784,9785,9786,9787,9788,9789,9791,9792,9793,9794,9796,9797,9801,9802
 20414 | 5088,8129,9745,9782,9795,9798,10161,10273
 20434 | 10615,10616,10617,10618,10619,10620,10621,10622,10623,10624,10625,10626,10627,10628,10629,10630,10631,10632,10633,10634,10635,10636,10637,10638,10639,10640,10641,10642,10643,10644,10645,10646,10647,10648,10649,10650,10651,10652,10653,10654,10655,10656,10657,10658,10659,10660,10661,10662,10927,10928,10929,10930,10931,10932,10933,10934,10935,10936,10937
 20470 | 10032,10033,10034,10035,10036,10037,10039,10040,10041,10044,10046,10047,10048,10049,10050,10051,10053,10054,10057,10058,10274,10294
 20479 | 6656,6657,6659,6664,6666,6814,6815,6816,6817,6818,6855,7880,7884,7974,7978,7981,7986,7989,8020,8134
 20491 | 4800,5082,10008,10073,10078,10087,10092,10094,10097,10104,10109,10110,10111,10116,10117,10119,10124,10126,10127,10284,10285,10288
 20538 | 7516,9822,10065,10066,10076,10080,10086,10099,10106,10118,10131,10137,10140,10141,10142,10144,10146,10147,10148,10149,10150,10153,10154,10156,10157,10158,10275,10282,10283,10287
 20567 | 10704,10705,10706,10707,10708,10709,10710,10711,10712,10713,10714,10715,10716,10717,10718,10719,10720,10721,10722,10723,10724,10725,10726,10727,10728,10729,10730,10731,10732,10733,10734,10735,10736
 20569 | 4391,4396,4404,4447,10737,10738,10739,10740,10741,10742,10743,10744,10745,10746,10747,10748,10749,10750,10751,10752,10753,10754,10755,10756,10757,10758,10759,10760,10761,10762,10763,10764,10765,10766,10767,10768,10769,10770,10771,10772,10773,10774,10775,10776,10777,10778,10779,10780,10781,10782,10783,10784,10785,10786,10787,10788,10789,10790,10791,10792,10793,10794,10795,10796,10797,10798,
 20572 | 10824,10825,10826,10827,10828,10829,10830,10831,10832,10833,10834,10835,10836,10837,10838,10839,10840,10841,10842,10843,10844,10845,10846,10847,10848,10849,10850,10851,10852,10853,10854,10855,10856,10857,10858,10859,10860,10861,10862,10863,10864,10865,10866,10867,10868,10869,10870,10871,10872,10873,10874,10875,10876,10877,10878,10879,10880,10881,10882,11236
 20578 | 6933,6941,6962,6973,6982,6985,7004,7018,7021,7026,7049,7103,7117,7151,7170,7174,7228,7277,7317,7319,7336,7337,7348,7357,7407,7416,7440,7467,7469,7493,7506,7522,7561,7564,7577,7583,7602,7603,7627,7638,7639,7648,7669,7674,7688,7690,7730,7822,8056
 20579 | 6951,6957,6983,6994,7000,7008,7015,7034,7036,7041,7084,7085,7086,7094,7120,7127,7129,7135,7152,7153,7156,7187,7202,7224,7234,7236,7246,7254,7260,7271,7275,7298,7360,7371,7374,7389,7435,7446,7454,7458,7463,7471,7482,7496,7504,7507,7530,7569,7571,7573,7599,7626,7643,7686,7692,7709,7724,7814,7816,7817,7819,7820
 20627 | 4467,10304,10305,10799,10800,10801,10802,10803,10804,10805,10806,10807,10808,10809,10810,10811,10812,10813,10814,10815,10816,10817,10818,10819,10820,10821,10822,10823,10883,10884,10885,10886,10887,10888,10889,10890,10891,10892,10893,10894,10895,10896,10897,10898,10899,10900,10901,10902,10903,10904,10905,10906,10907,10908,10909,11232
 20631 | 7516,9803,9805,9807,9809,9810,9811,9812,9815,9818,9821,9823,9824,9825,10159
 20830 | 5031,6093,10910,10911,10912,10913,10914,10915,10916,10917,10918,10919,10920,10921,10922,10923,10924,10925,10926
 20836 | 4574,5442,5485,5613,5716,5797,5832,5846,5883,5985,6093,6173,6176,6216,6446
 20840 | 9853,9982,9983,9984,9986,9992,9993,9994,9995,10001,10002,10003,10004,10005,10006,10007,10009,10010,10011,10012,10013,10014,10015,10016,10017,10018,10021,10022,10023,10026,10027,10028,10212,10296
 20913 | 5068,5771,5918,5925,6007,6011,6012,6061,6087,6129,6170,6391,6447,10561,10562,10563,10564,10565,10566,10567,10568,10569,10570,10571,10572,10573,10574,10575
 20966 | 3918,4255,4264,4995,6965,6974,7024,7038,7039,7080,7082,7200,7223,7269,7321,7331,7377,7418,7421,7422,7431,7436,7479,7535,7589,7590,7591,7611,7616,7633,7635,7704,7717,7722,7725
 20969 | 2884,3881,3913,3915,3916,3917,3968,3969,3970,3971,4062,4063,4064,4251,4252,4253,4254,4257,4259,4260,4261,4262,4263,4264,4458,4514,4515,6967,7040,7090,7140,7145,7161,7279,7285,7296,7314,7380,7382,7400,7423,7434,7453,7464,7488,7501,7518,7531,7541,7565,7640,7645,7659,7666,7697,7718,7823

我必须将每个集合拆分成更小的集合,因此它可能只包含3到5个数字,具有以下配置:

function splitter( n ) { 
var z, res = [];
    if( n % 5==0 ) {
        for( z = 0; z<n / 5; ++z ) res.push( 5 );
        return res;
    }
    if( n<15 ) {
        return {
            2: [ 2 ],
            3: [ 3 ],
            4: [ 4 ],
            6: [ 3, 3 ],
            7: [ 4, 3 ],
            8: [ 4, 4 ],
            9: [ 5, 4 ],
            11: [ 4, 4, 3 ],
            12: [ 4, 4, 4 ],
            13: [ 5, 4, 4 ],
            14: [ 5, 5, 4 ]
        }[ n ]
    }
    var m = n - (5 - n % 5) * 4;
    for( var z = 0; z<m / 5; ++z ) res.push( 5 );
    for( z = 0; z<(5 - n % 5); ++z ) res.push( 4 );
    return res;
}

例如:

sets with 21 numbers, will be splitted into 5 smaller sets containing [5,5,4,4,4] numbers each
sets with 34 numbers, will be splitted into 7 smaller sets containing [5,5,5,5,5,5,4] numbers each
sets with 17 numbers, will be splitted into 4 smaller sets containing [5,4,4,4] numbers each

更详细的例子,

sets with 17 items (1,2,3,4,5,6,9,12,14,18,21,22,25,29,40,32,54)
should be splitted into `smaller set`s with [5,4,4,4] items each, for example:

1,2,3,4,5; 6,9,12,14; 18,21,22,25; 29,32,40,54;

or

1,2,3,14,18; 21,4,5,6; 12,22,25,9; 29,40,32,54;

or any other combination of smaller sets with:
  1 set containing 5 numbers [5]
  and 3 sets containing 4 numbers [4,4,4]

使用生成smaller set所有smaller set的所有duplicate pair标准生成duplicate pair的最快算法是什么?

smaller set表示在1,2,3,4,5; and 1,2,3,14,18; 内,例如:

1,2

包含3个重复对:1,3(2),2,3(2)和smaller set(2)

对于这些1,2,3,4,5; and 1,2,6,9; and 1,4,6,9; s的重复对的另一个示例:

1,2

包含5个重复对:1,4(2),1,6(2),1,9(2),6,9(2),on = IP_PMTUDISC_DO; // sets the Don't-Fragment flag setsockopt(fd, SOL_IP, IP_MTU_DISCOVER, &on, sizeof(on)); // Set or receive the Path MTU Discovery setting for a socket. When enabled, Linux will perform Path MTU Discovery setsockopt(fd, SOL_IP, IP_RECVERR, &on, sizeof(on)); // Enable extended reliable error message passing. When enabled on a datagram socket, all generated errors will be queued in a per-socket error queue. // When the user receives an error from a socket operation, the errors can be received by calling recvmsg(2) with the MSG_ERRQUEUE flag set. setsockopt(fd, SOL_IP, IP_RECVTTL, &on, sizeof(on)); // When this flag is set, pass a IP_TTL control message with the time to live field of the received packet as a byte. Not supported for SOCK_STREAM sockets. ( 2)

0 个答案:

没有答案