资源描述:
《百度技术研发笔试题目》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、百度技术研发笔试题目BaiduR&Dwrittenquestions/*Baiduinterviewquestions*a27cmfinewood,inthirdcm,7cm,11cm,17cm,23cmandfivepositionseachhaveanant・*woodisveryfine,notbyanantatthesametime・Atthebeginning,theantsheadtowardstheleftorrightisarbitrary,theywillonlygoaheadorturnaround,
2、*butnotbackward.Whenanytwoantsmeet,twoantsturnbackandwalkintheoppositedirection.Assumethattheantscanwalkdistaneeofonecentimeterpersecond・*writeaprogramforallantsleavetheminimumtimeandthemaximumtimeofthepole・***analysis:inthetitleofantsmaymeetintheintegerpoints,ca
3、nnotmeetatotherpoints,suchas3.5cm,thatis,eachantcanletgoasecond,then*toseeiftherearemet・I*programsuchideasisthattheinitializatdonof5ants,leteachantgo1,andseewhethertherearemet,ifthereisacorrespondingtreatmentwheneveryant・WhenIwasoutofthewoods:*,recordsthecurrentt
4、ime・Sowecangetthecurrentstatus,howlongcanbeoutofthewoods,andthentraverseallthestatecanbeobtainedbyHu*・*/Packagebaidu;Publicclass{Ant**stepsaidtakeantseveryunitlengthoftime*/PrivatefinalstaticintStep二1;**positionsaidtheinitialpositionoftheant*/Privateintposition;*
5、directionsaidthedirectionofants,if1to27cmdirection,if1,saidtothe0direction・*/Privateintdirection二1:**thisfunctiononce,saidtheantforwardaunitoftime,ifyouhavewalkeddownthewoodenexceptionisraised*/Publicvoid(walk){If((isOut)){ThrownewRuntimeException("theantisout");
6、}Position二position+this.direction*step;};Checkwhethertheant*hasbeenoutofthewoods,ifoutofthereturntrue**/PublicBoolean(isOut){Returnposition0
7、
8、〈position〉二27;/**Theant*checkwhetherhavemetanotherant*@paramantIfyoureturntrue*@return*/PublicBooleanisEncounter(Antant){
9、Returnant.position二二this.position;*thedirectionchangeofants*/Publicvoid(changeDistation){Direction二一1*direction;/***constructor,thedirectionoftheinitialsetofants,andtheinitialposition*@paramposition*@paramdirection*/PublicAnt(intposition,intdirection){This・positi
10、on二position;If(direction!二1){This.direction二T;//setthedirectionoftheinitialposition,suchas0,willbesetto1.soyoucaneasily.{else}This.direction二1;////////////////