Problem Statement
John is locked in a mansion that is shaped like a star, with a number of corridors of distinct length that meet at a common point in the center. He is desperately looking for an exit, so he wants to check the end of every corridor to see if he can find one.
He is initially at the outer end of one of the corridors. In his desperation, he does not develop a good strategy, and instead, decides to do the following: He will run to the center, and when he gets there, he will randomly enter a different corridor than the one he came from. He will then run to the outer end of that corridor, turn back, and return to the center, where he will again randomly enter a different corridor than the one he just came from (but possibly a corridor he was in before that). He will repeat this process until he has visited the outer ends of all the corridors at least once. When he reaches the end of the final corridor, he will not run back to the center again.
You will be given a
Definition
- Class:
- CrazyRunning
- Method:
- expectedTime
- Parameters:
- int[]
- Returns:
- double
- Method signature:
- double expectedTime(int[] corridors)
- (be sure your method is public)
Notes
- John will not stop running until he has visited every corridor end.
- The returned value must be accurate to within a relative or absolute value of 1E-9.
Constraints
- corridors will contain between 2 and 50 elements, inclusive.
- Each element of corridors will be between 1 and 1000000 (106), inclusive.
Examples
{10,20}
Returns: 30.0
He starts at the end of corridor 0 at time 0. At time 10 he is in the center, and his only option (since he never goes back to the same corridor he just came from) is to go to corridor 1. He reaches the end of corridor 1 at time 30.
{150,150,150}
Returns: 900.0
He will start from corridor 0, get to the center at time 150, enter one of the other two corridors, run to the end and back to the center at time 450. From that moment on, he has 1/2 probability to finish in 150 seconds and 1/2 to do a useless run for 300 seconds and be in the same position again. So the answer is 450 + 1/2*150 + 1/2*1/2*450 + ... + ((1/2)n*((n-1)*300+150)) + ..., which is equal to 900.
{100,150,200}
Returns: 875.0
{1000,1000,900,1000,555,1000,2562}
Returns: 33550.32857142857
{1,1}
Returns: 2.0
{1000000,999998,999999}
Returns: 5999994.5
{1000000,999998,999999,1000000,999998,999999,1000000,999998,999999,1000000,999998,999999, 1000000,999998,999999,1000000,999998,999999,1000000,999998,999999,1000000,999998,999999, 1000000,999998,999999,1000000,999998,999999,1000000,999998,999999,1000000,999998,999999, 1000000,999998,999999,1000000,999998,999999,1000000,999998,999999,1000000,999998,999999, 50,50}
Returns: 4.214432774053318E8
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
Returns: 438.9621231562802
{1,1,1,1,1,1,1}
Returns: 29.39999999999996
{10,10,10,10,10,10,10}
Returns: 293.9999999999998
{1,1000000}
Returns: 1000001.0
{1000000,1}
Returns: 1000001.0
{1,1000000,1000000}
Returns: 3666669.0
{1000000,1,1}
Returns: 2333337.0
{999996,999990,1000000,999992,999993,999998,999999,999998,999993,999990,999991,999997,999999,999996,999991,999994,999998,1000000,999997,999996,999992,999993,999997,999995,999992,999996,999995,1000000,999997,999999,999997,999995,999999,999999,999997,999995,999993,999993,999999,999993,999992,999990,999994,999991,999992,999999,999998,999996,999999,999997}
Returns: 4.3896012203757125E8
{999992,999996,999992,999991,999991,999999,999990,999998,999992,999995,999996,999993,1000000,999999,999995,999999,999994,999995,1000000,999997,999999,999999,999995,999996,1000000,1000000,999996,999990,999991,999994}
Returns: 2.2977487526208362E8
{999992,999990,999998,999993,999994,999990,999996,999997,999998,999996,999992,999999,999996,999991,999996,999992,1000000,999994,999992,999994,999991,999990,999993,999991,999995,1000000,999992,999992,999997,999996,999996,999997,999990,999992,999997,999991,999994}
Returns: 3.005665053983368E8
{999998,999999,999997,999997,999993,999990,999992,999991,999994,999995,999993}
Returns: 5.857904342106786E7
{999998,999990,999999,999994,999996,999994,999995,999996,999992,999993,999993,999993,999994,999995,999995,999991,999995,999991,1000000,999995,999999,999999,1000000,1000000,1000000,999994,999994,999990}
Returns: 2.1013765422398093E8
{999996,999996,999997,999996,999994,999992,999990,999992,999992,999995,999996,999996,999993,999998,999990,999991,1000000,999996,1000000,1000000,999996,999995,999990,999997,999991,999999,999995,999991,999998,999997,999995,999997,999995,999990,999998,999995,999992,999996,999998,999996}
Returns: 3.317747073996591E8
{999999,999998,999995,999993,999992}
Returns: 1.6666592699999992E7
{999997,999995,999993,999998,999992,999996,999999,999991,999997,999990,999990,999990,999996,999999,999994,999994,999997,999998,999992,999993,999990,999998,999997,999997,999997,999996,999990,999993,999997,999997,999997,999993,999990,999995,1000000,999990}
Returns: 2.90273153466115E8
{999998,999994,1000000,999995,999999,999991,1000000,999992,999998,999990,999992,999993,999993,999994,999996,999990,1000000,999999,999991,1000000,999993,999999,999992,999998,999999,999996,999994,999995}
Returns: 2.1013769904734597E8
{999999,999992,999997,999991,999999,999990,999992,999994,999991,999994,999990,999998,999993,999994,999998,999992,999993,999994,999994,999990,999997,1000000,999990}
Returns: 1.6239481340758893E8
{5,6,6,10,4,4,7,9,2,5,8,1,1,7,7,5,9,10,7,8,7,2,10,4,2,4,5,6,2,5,9,9,2,9,2,6,9,9,10,3,9,2,4,4,2,9,6,10,1,7}
Returns: 2545.196640837042
{2,2,6,7,3,1,6,3,10,2,5,6,7,4,2,5,10,10,8,7,5,6,9,6,3,4,4,7,8,1,7,6,5,9,1,4,8,8,4,5,6,4,10,9,7,6,8}
Returns: 2296.1044556214083
{5,7,7,1,8,3,1,2,10,8,8}
Returns: 319.1147186147183
{8,1,6,4,3,4}
Returns: 101.87777777777784
{4,8,1,1,5,8,2,10,1,5,4,4,5,8}
Returns: 389.13419675562477
{10,3,1,6,4,8,4,7,1,2,5,5,3,3,2,5,4,3}
Returns: 499.2047817469384
{6,9,1,1,10,6,10,1,9,4,8,7,9,8,6,2,6,4,10,7,5,4,2,1,6}
Returns: 1029.7839042493788
{9,10,9,5,7,10,4,6,9,6,5,10,5,2,4,3,6}
Returns: 702.3810915391787
{1,1,5,1,1,8,3,5,6,2,1,2,1,3,4,5,7,2,4,7,8,1,10,7,4,9,7,5,1,2,5,7}
Returns: 1050.261402076522
{5,3,9,7,10,2,8,7,3,7,5,4,6,9,2,9,5,10,5,10,5,5,7,1,3,7}
Returns: 1129.224537257766
{26411,24946,6420,63874,31373,450054,26,12796,9573,21351,8607,152533,73436,112643,79266,51392,31966,98,94945,20140,94520,138250,14749,10116,7908,60491,19454,110331,22004,73414,119605,2513,17356,26349,169967,160862,46415,353902,146177,66142,18619,235887,78012,33380,9106,127859,4334,59604,3256,24890}
Returns: 3.0923980366782606E7
{163810,8277,19426,36743,42535,64627,219,52215,35245,42,128974,38585,17628,1921,12709,32940,10004,26896,50881,1730,80100,483,937,12509,107061,5406,5416,28030,47732}
Returns: 7957980.975959159
{14646,47636,40498,429,54000,1027,6879,5005,77663,1972,142553,21448,934,220,639,92124,1763,109396,6978,436,34055}
Returns: 4508978.356384057
{24876,364,6094,42090,2856,3038,863,10479,11136,182483,173401,40474,16157,1399,446771,7836,74917,8246,55192,75940,45749,22299,129986,14,1645,17138,223348,45528,15764,811,3485,18467,108229,53349,241853,25571,247073,135818,25011}
Returns: 2.0935068579892736E7
{1823,40264,48172,22914,2597,6135,30937,12601,5437,45029,257,61291,1455,126676,86953,228440,109902,89981,228033,19136,7225,39561,40382,9506,2356,2538,49356,44438,175212,2441,792,41025,192776,100393,99690}
Returns: 1.5754933238366645E7
{10271,22497,2358,37648,569,69117,50072,448002,126,24136,325,1649,10924,10844,7591,3693,30585,27637,256,28290,5549,61566,63669}
Returns: 6449021.260745976
{384699,18892,2220,10302,89965,146307,1156,22071,27708,31819,2353,332160,25696,202,1350,5513,8261,105676,53056,4774,144,26678,8219,51126,660,135864,23397,133408,34723,74453,10523,56284,1894,571,33947}
Returns: 1.52522450500051E7
{81615,19195,51628,149808,95,115859,8473,177867,26070,887,60043,119680,462,17604,4285,48,1791,28461,175596,5191,40093,364,934,5787,3298,47270,737,85,176016,110669}
Returns: 1.0984751096016115E7
{4967,109490,202389,136134,8393,26130,7223,28290,148381,61358,46588,28771,14329,17946,10264,1301,17356,225187,9312,50623,18709,2151,80401,4806,40866,27518,21008,6918,20072,1677,12824,36937,5,31850,63246,3944,106456,4741,39436,53924}
Returns: 1.4327912823193379E7
{27358,1902,2755,11975,383,4274,111205,189197,55143,29922,58864,82968,6750,296,90700,876,3719,136992,301754,12502,15523,19170,49392,19859,12579,6475,16679,11828,36724,39762,20714,75870,4364,70498,39087,7862,1446,4765,67803,38648,8867,2467,103365}
Returns: 1.5227543752113206E7
{659604,226390,26005,878051,641037,750026,875110,959125,282258,141811,213013,666458,934084,591664,32588,493164,770293,606456,878504,777626,131888,127380,493629,921801,770414,455776,216080,319662,874785,159311,922906,618324,488557,745764,691596,558236,120874,218937,139077,466232,846372,705019,478877,7407,901339,846764,321054,491612,785795,858336}
Returns: 2.3791942114612326E8
{250479,960453,577025,484167,527915,450300,782347,148295,318118,961977,381264,79712,815500,46592,450421,615584,353244,998024,718515,758154,379690,476735,127191}
Returns: 8.209472849863875E7
{726875,155908,233155,870310,48044,937579,254955,518817,383275,313980,34456,845334,279420,782452,249704,495563,693654,610178,648652,306362,246788,604044,780745,196625,227364,885416,495096,702963,51627,252067,690054,897846,245151,701117,485877}
Returns: 1.350682414847534E8
{905051,407787,83033,182521,855567,553428,526811,197546,407549,437653,247929,155484,196413,152701,477252,31786,599290,222097,738721,886496,771955,506697,167881,760066,141499,304272,400585,395142,60346}
Returns: 8.976605128079183E7
{98178,175317,210729,202309,289194,184655,432729,314317,134281,984964,967277,746655,499389,783739,301980,197352,854135,123310,383920,302159,731964,247692,82377,958443,983205,834614,681691,359559,507743,757827,690988,525477,255915,469053,871511,888568,29087,966753,277963,88680,982307}
Returns: 1.697343943218605E8
{804492,314770,713973,179559,760497,44677,393445,624521,738661,741575,729754,404309,815591,382414,109452,360592,135050,484231,567688,729838,799093,151378,34223,492826,420835,505220,380406,212273,25508,864612,536487,941447,392219,87406,261471,482336,80318,818900,852751,500984,756313,105591,205179,599100,837516,940658,727422,759503,115848,789776}
Returns: 2.1726258671492317E8
{780422,608277,819089,684558,280044,732303,201641,916913,879166,551589,748801,856663,691440,543641,669876,400893,73191}
Returns: 6.65837823330624E7
{369683,493684,148861,607693,709602,225824,988928,968952,906008,456316,367090,250773,858979,430803,751755,395213,904865,118216,433651,888538,500072,199888,552585,875788,827647,55859,841950,280902,360163,952910,542330,259262}
Returns: 1.365699876849211E8
{73876,50134,352768,471429,101000,234593,43115,825855}
Returns: 9600862.232142858
{990204,826418,483518,6326,563965,514588,764546,135774,601711,246789,768,901393,288784,292379,945695,226745,660818,933538,861819,561874,205339,860464,375718,273007,797573,64050,517793,963763}
Returns: 1.120060976361864E8
{815205,841959,703448,259370,666142,147811,595692,895389,530114,676021,197711,805217,987983,94833,549942,574613,886481,385952,285675,944715,556525,22013,663114,750729,323610,386809,979781,61834,867107,569847,508769,6715,216743,665553,152760,850430,122009,996177,62517,797226}
Returns: 1.7781092556805465E8
{93497,137307,110344,887416,644732,719294,15447,501487,443842,423688,346890,864680,995176,384565,461381,529851,958397,193623,566755,383572,303494,147,932787,2992,20283,411362,844791,820771,160457,831890,46116,270549,294862,382338,87268,126016,910495,519913,647319,771763,787653}
Returns: 1.5688667666871637E8
{344205,945746,177596,63251,25742,922004,829363,450724,564946,222596,857935,681672,317257,72640,871655,274712,401877,696445,366857,316609,78603,495745,217908,151365,965942,446311,721756,689336,75603,925919,360298,458883,975190,645611,625401,507428,792228}
Returns: 1.5043516665474933E8
{300250,816044,198294,973043,941904,137280,95549,82648,623573,329305,668632,23206,616147,908996,89376,781508,525868,970467,87164,29230,953330,10409,819917,114738,862768,914274,167588,920948,316767,504873,318279,572074,978866,563632,268592,211361,342027,774588,666317,546422,757827,952485,320897,604062,601766,989018,96865,867871}
Returns: 2.189413382640105E8
{123804,230136,748372,270946,318974}
Returns: 5479791.533333332
{534124,656087,761772,25463,101228,307887,216417,599671,637609,231291,922286,368542,108302,86783,661114,899387,670044,481779,566909,956431,131173,390083,949060,943248,515088,617102,522672,350250}
Returns: 1.0668447219931597E8
{131307,496119,748473,433038}
Returns: 4760625.249999999
{335777,992912,175955,478632,593676,95605,471582,599798,747944,783586,723899,577516,589820,808134}
Returns: 4.688321849712348E7
{924708,648288,701890,538684,190888,685441,483117,528729,583354,416,95632,69437,298509,410514,90474,7447,513801,827329,755950,540137,950667,699178,736320,242251,450466,72862,622779,712551,777171,628225,262446,315582,359446,586446,769755,420450,619671,238032,976758,603578,365878,951979,487276,627585,130952,910417,514905,309767,156628}
Returns: 2.135209448030224E8
{627601,634030,603862,582844,595672,39855,391103,916750,786218,3219,54323,667594,242868,40634,816970,758791,770328,841623,722383,241012,926189,61489,902468,759825,722429,267172,843548,733491,881478}
Returns: 1.2469937563949206E8
{730688,634180,293817,819939,141899,692480,120318,647306,238605,213562,702829,996029,404684,357333,70103,118781,53758,268172,850555,879771,696465,381674,140817,113664}
Returns: 7.591298575800401E7
{302546,756547,70886,925770,826296,906351,459101,871565,540454,649639,185607,346281,561721,769392,23836,150029,499489,887366,5287,811486,424868,757527,612615,100788,910043,620675,403375,686171,843380,991651,631142,74963,347887,270463,264840,912337,893665,998358}
Returns: 1.7398066547970307E8
{5692,578996,766297,831194,371504,933156,87856,952294,458558,904963,768692,365584,590250,519670,240500,695448,780075,689014,227697,686610,306991,698705,738913,210403,861013,389094}
Returns: 1.0703877158888566E8
{95496,940145,431341,390073,333072,834188,797228,637137,8221,162977,980034,633214,908327,190176,605793,697784,423992,338927,983820,852206,331569,122596,400477,896515,48836,121292,131009,982989}
Returns: 1.0676733864716314E8
{767016,743162,350549,370920,543914,693340}
Returns: 1.3352188138888886E7
{474564,234365,255056,915279,882383,293242,510548,688216,740319,292852,412665,332880,162528,889389,401188,77126,79633,335646,696462,192187,698693,326451,311172,754726,993316,685516,837736,585777,624615,311421,593454,335097,31264,325391,934431,881041,574192,609405,345305,908672}
Returns: 1.702812802179231E8
{308856,599629,992126,280839,159332,48384,445051,34936,32153,274187,274137,537430,34018,906203,236397,631719,390529,924274,122625,861254,260969,287395,78933,912099,115651,993498,253209,798464,265898,194194,675701,78133,87854,297181,653633,179053,242773,574879,629197}
Returns: 1.2903739905409782E8
{34069,269203,740187,290102,375835,537861,589984}
Returns: 1.1607036247619035E7
{709064,946838,432903,581508,463982,336444,175918,235021,142359,348735,926694,642943,109887,427005,95863,358803,172181,459559,832090,786130,893630,355458,323133,567900,241362,993382,880771,341541,463453,323906,317505,163379}
Returns: 1.1765792723709422E8
{804311,263042,593505,651725,929016,198724,163166,897614,256592,489208,887982,844990,753628,550342,548840,26158,20717,956423,305591,722273,326631,232906,766745,90705,451269,646288,318499,912297,951635,580943,589691,278024,858802,19314,594525,567940,11735,347095,396439,16869,117068,934032,588556,285478,994734,47395,91060,642935,549550,893962}
Returns: 2.194898221297287E8
{966206,994320,19316,898910,514769,471151}
Returns: 1.4964899199999984E7
{220529,899453,604470,980618,64411,711363,878184,415384,876216,74965,805850,898856,712630}
Returns: 4.627884618408259E7
{572020,783277,557785,618615,311028,550093,284728}
Returns: 1.5484573438095218E7
{111018,204642,850686}
Returns: 2193810.0
{426044,290043}
Returns: 716087.0
{786386,90276,37721,576078,523995,354925,678515,184083,124110,839290,955826,135987,531264,741504,119350,196926,811639,54215,30223,785110,175154,203372,746948,56307,2015,495585}
Returns: 7.54985253697301E7
{557984,965282,865580,771488,512828,2133,202468,904470,933818,413826,968312,242185,917985,35947,91815,706818,632653,184451,621897,417345}
Returns: 7.381587004149742E7
{50,336516,778934,534530}
Returns: 4262610.833333334
{152280,789705,836133,587132,899284,656530,639297,535530,511582,202401,746838,434776,263088,8888,469685,668083,484437,768076,797127,528217,30704,787656,998086,392992,328053,443529,252354,160143,269806,957155,442845,752482,724151,465178,452367,948363,694402,257770,507234,380716,91412,79744,189303,148125,616774,608703,953792,980140,635846,372924}
Returns: 2.2704022370627373E8
{702488,390995,780930,138590,437334,597572,672271,653758,718412,45058,668949,257767,258457,530569,56249,269807,804299,913195,504791,12738,496550,770893,306173,595487,283940,817257}
Returns: 9.328994465634882E7
{725914,932783,429578,218650,946392}
Returns: 1.0900827949999994E7
{215058,289522,620438,224997,926263,270610,982050,925099,676930,325644,550560,990968,875791,185830,247687,762812,575440,297690,535650,218842,892170,894998,864079,553451,659926,181757,556227,670203,794721,872869,167684,704779,270700,314071,251693,905421,404173,130962,178926,75627,708973,514952,552457,137217,502472,267871,718038,255454}
Returns: 2.1437270655944887E8
{745585,795904,125191,6345,585037,266758,614772,764110,395828,686139,775185,574539,948381,698631,101054,534754,490289,180515,783,174599,936783,714848,354637,672259,648201}
Returns: 9.29578127721341E7
{995187,780404,277862,123677,340914,568139,166622,337118,35053,939148,971553,218564,146366,376082,718032,16899,457519,632585,78274,795617,94338,676786,982593,313273,78570,844003,162442,884090,705039,757764,960528,694376,752078,386707,793594,731162}
Returns: 1.5199075910378683E8
{532513,702688,395643,944141,823635,408018,892874,224457,115041,615122,789914,299927,459546,391765,186130,831512,771870,164549,85165,693854,424547,843842,771771,213235,299953,281372,669727,836947,723942,241371,81551,799725,716658,24504,900439,770150,1884,842273,803095,43926,194619,861176,324544,413896,402622,940052,224922,315902,620581}
Returns: 2.17693655652499E8
{49985,512300,555526,586487}
Returns: 4436093.166666667
{371192,555337,231150,541253,691264,338156,2377,925051,630548,964031,855844,571379,90744,959529,660493,57003,844771,750369,472068,796661,931331,436086,885058,541178,276214,68744,923183,774004,474322,765452,8233,416115,847263,473036,286788}
Returns: 1.5517289284693825E8
{358743,762981,765125,737183,969197,999559,482150,403022,594243,202488,326934,168006,625266,545042,803829,689466,545670,808832,794396,489585,35584,466053,103379,966983,696466,824694,936025,35818,453222,178554,486816,950750,961048,610001,877966,366457,83447,953738}
Returns: 1.80269475735377E8
{697192,440200,765516,227836,276712,240131,132302,290444,80462,806803,77086,379171,732160,68506,240222,344173,875385,733803,548802,151494,231048,955663,621012,275329,258513,247041,830897,414692,706507,679410,297161,183082,350081,931654,376034,794623,962002,171284,889557,156872}
Returns: 1.5318616517200324E8
{859049,71632,657816,139941,148934,708178,908348,307274,252062,257266,547184,230542,166425,56921}
Returns: 3.181270081641692E7
{820563,859078,996499,853499,862389,897724,987366,975104,975309,994484,985367,945939,999923,999229,994807,818013,827496,871074,994479,725697,999692,981019,997417,998136,900295,999110,993681,828085,992069,907827,999335,980000,999440,874927,919140,921128,996710,867858,869919,950884,973085,995637,996258,986091,851820,840381,883461,961237,996901,875342}
Returns: 4.1006278799848866E8
{994888,984884,817812,989333,995718,999707,791638}
Returns: 2.7657172666666623E7
{962299,999139,980448,975352,737254,999496,992544,864318,988151,959397,943069,831049,990459,985308,917328,991706,978233}
Returns: 1.024421896288493E8
{974392,990225,998761,973953,720377,975965,977307,999116,999904,987743,942000,943002,963609,957706,889622,971200,999281,996250,981350,808352,999415,949376,897171,973773,975451,959221,994352,867995,996067,992200,870719,903142,994478,968332}
Returns: 2.571173626242708E8
{974684,998084,881158,988902,988506,861294,988408}
Returns: 2.8077226438095216E7
{941067,969780,1000000,997465,896792,823897,991384,999138,882271,859614,991765,992318,997341,979123,843253,932653,997265,917906,619417,992557,938542}
Returns: 1.340748102386358E8
{975293,872864,950846,973989,994835,999266,862430,994562,981381,976405,998626,975381,949501,995777,853471,856339,979725,980664,929979,929226,990510,947559,950161,869936,975084,818435,979145,975619}
Returns: 1.9918550957024744E8
{999897,651158,999947,988902,956320,717230,842854,996982,858298,990566,973592,898876,995966,923780,998087,993194,942947,977763,991238,990087,909543,953567,967917,986018,954724,996807,997744,944423,992134,947667,885543,826056,896351,942886,961928,950611,973877,982469,890687}
Returns: 3.020062964438213E8
{999062,902709,987385,995256,919487,910899,613951,946454,857175,834072}
Returns: 4.57494816547619E7
{100000, 98, 123, 98, 345, 456, 997, 35, 35000, 1000, 100, 10, 1, 15, 99999, 99876, 7645, 223, 4545, 7000, 1000, 1111, 100000, 98, 123, 98, 345, 456, 997, 35, 35000, 1000, 100, 10, 1, 15, 99999, 99876, 7645, 223, 4545, 7000, 1000, 1111, 35, 35000, 1000, 100, 87654, 2 }
Returns: 7483614.811061859
{1000, 1000, 900, 1000, 555, 1000, 2562 }
Returns: 33550.32857142857