Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Cooking Machine - CodeChef

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

8/27/2015

CookingMachine|CodeChef

Hellosumer098!
AccountorLogOut

PRACTICE

COMPETE

DISCUSS

COMMUNITY

HELP

ABOUT

HomePractice(school)CookingMachine

CookingMachine
Problemcode:COOKMACH
Like

ALLSUBMISSIONS

MYSUBMISSIONS

SUBMIT

Share 5peoplelikethis.Bethefirstofyourfriends.

Allsubmissionsforthisproblemareavailable.

SUCCESSFULSUBMISSIONS

ReadproblemsstatementsinMandarinChineseandRussian.
Chefisonavacationthesedays,sohisfriendChefzaistryingtosolveChef'severydaytasks.

User

Score Mem

Lang

Solution

fazal

100.000 2M

View

bhavaniab

100.000 2M

View

kri1311

100.000 2M

View

krish23493

100.000 2M

View

varun0402

100.000 2M

View

rohitlien5759

100.000 2M

View

tarojung

100.000 2M

View

rishabhkatiyar

100.000 2M

View

laksh007

100.000 2M

View

shubhangipri

100.000 2M

View

Output

hemang_sarkar

100.000 2M

View

For each test case, output a single line containing minimum number of operations Chefza has to
performinordertosetupthemachine.

neeraj19

100.000 2M

View

Today's task is to make a sweet roll. Rolls are made by a newly invented cooking machine. The
machineisprettyuniversalitcanmakelotsofdishesandChefzaisthrilledaboutthis.
Tomakearoll,Chefzahastosetallthesettingstospecifiedintegervalues.Therearelotsofsettings,
eachofthemsettosomeinitialvalue.Themachineisprettycomplexandthereisalotofcookingtobe
donetoday,soChefzahasdecidedtouseonlytwoquickwaystochangethesettings.Inaunitoftime,
hecanpickonesetting(let'ssayitscurrentvalueisv)andchangeitinoneofthefollowingways.
Ifviseven,changethissettingtov/2.Ifvisodd,changeitto(v1)/2.
Changesettingto2v
Thereceiptisgivenasalistofintegervaluesthesettingsshouldbesetto.Itisguaranteedthateach
destinationsettingcanberepresentedasanintegerpowerof2.
SinceChefzahasjustchangedhisprofession,hehasalotofotherthingstodo.Pleasehelphimfind
theminimumnumberofoperationsneededtosetupaparticularsettingofthemachine.Youcanprove
thatitcanbedoneinfinitetime.

Input
ThefirstlineoftheinputcontainsanintegerTdenotingthenumberoftestcases.ThedescriptionofT
testcasesfollows.
TheonlylineofeachtestcasecontainstwointegersAandBdenotingtheinitialanddesiredvaluesof
thesetting,respectively.

Constraints
1of28

1T200
1A107
1B107 ,andBisanintegerpowerof2

HELP

Subtasks
Subtask#1[40points]:A100andB100
Subtask#2[60points]:Noadditionalconstraints

Example
Input:
6
11
24
38
416
41
14
Output:
0
1
4
2
2
2

Explanation
Inthefirsttestcase,youdon'tneedtodoanything.

https://www.codechef.com/problems/COOKMACH

Program should read from standard input and write to


standardoutput.After you submit a solution you can see
yourresultsbyclickingonthe[MySubmissions]tabonthe
problempage.Belowarethepossibleresults:

Accepted Your program ran successfully and


gave a correct answer. If there is a score for the
problem, this will be displayed in parenthesis next to
thecheckmark.
Time Limit Exceeded Your program was
compiledsuccessfully,butitdidn'tstopbeforetimelimit.
Tryoptimizingyourapproach.
Wrong Answer Your program compiled and ran
succesfully but the output did not match the expected
output.
Runtime Error

Your code compiled and ran but

1/3

8/27/2015

CookingMachine|CodeChef
Inthesecondtestcase,youneedtomultiply2by2andget4.Thisisdonein1operation.
Inthethirdtestcase,youneedtoobtain1from3andthenmultiplyitby2threetimestoobtain8.
Atotalof4operations.
Inthefourthtestcase,multiply4by2twice.
Inthefifthtestcase,divide4by2twice.
Inthesixthtestcase,multiply1by2twice.

Author:

cenadar

Tester:

laycurse

Editorial

http://discuss.codechef.com/problems/COOKMACH

Tags

cenadar

encountered an error. The most common reasons are


using too much memory or dividing by zero. For the
specificerrorcodesseethehelpsection.
Compilation Error Your code was unable to
compile. When you see this icon, click on it for more
information.
If you are still having problems, see a sample solution
here.

DateAdded: 26052015
TimeLimit:

1sec

SourceLimit: 50000Bytes

Languages:

ADA,ASM,BASH,BF,C,C99strict,CAML,CLOJ,CLPS,CPP4.3.2,CPP4.9.2,CPP14,
CS2,D,ERL,FORT,FS,GO,HASK,ICK,ICON,JAVA,JS,LISPclisp,LISPsbcl,LUA,
NEM,NICE,NODEJS,PASfpc,PASgpc,PERL,PERL6,PHP,PIKE,PRLG,PYPY,
PYTH,PYTH3.1.2,RUBY,SCALA,SCMchicken,SCMguile,SCMqobi,ST,TCL,TEXT,
WSPC

SUBMIT

Comments
tausif000@18Aug201505:40AM
soundsbinary

deepak12yadav@18Aug201512:59PM
WHATISWRONGINTHISPROGRAM?ITISGIVINGTHEDESIRABLEOUTPUT.#includemain(){
int T,A,B,d=0,i scanf(" %d",&T) for(i=1i<=Ti=i+1) { scanf(" %d %d",&A,&B) while(B!=A) {
if(A%2==0||A==1){if(B>A){A*=2d++}else{A/=2d++}}else{A=(A1)/2d++}}printf("%dn",d)
}}

rohitlien5759@18Aug201511:43PM
@deepak12yadavtestursolutionforA=6andB=16

gauravrana3450@19Aug201503:44PM
pleasedescribehowtocode.injava

somyasr7@19Aug201507:48PM
myprogramgivesaruntimeerror..whatshouldido?

hitman333@20Aug201505:39PM
whyitisshowingruntimeerror

hitman333@20Aug201510:13PM
https://ideone.com/D7Oqy5checkmycodeatthislink,outputiscorrect..thenwhyonsubmittingits
showingwronganswer...plzzzreply

Needhelp?Postacomment.Butbeforethatpleasespareamomenttoreadtheguidelines.
Yourname:
sumer098
Comment:*

Save

https://www.codechef.com/problems/COOKMACH

2/3

8/27/2015

CookingMachine|CodeChef

CodeChefisanoncommercialcompetitiveprogrammingcommunity

AboutCodeChef AboutDirecti CEO'sCorner CProgramming ProgrammingLanguages ContactUs


2009DirectiGroup.AllRightsReserved.CodeChefusesSPOJbySphereResearchLabs
Inordertoreportcopyrightviolationsofanykind,sendinanemailtocopyright@codechef.com

Thetimenowis:12:58:30AM
YourIp:125.20.9.248

CodeChefAPlatformforAspiringProgrammers
CodeChefwascreatedasaplatformtohelpprogrammersmakeitbigintheworldofalgorithms,computerprogrammingandprogrammingcontests.AtCodeChefweworkhardto
revivethegeekinyoubyhostingaprogrammingcontestatthestartofthemonthandanothersmallerprogrammingchallengeinthemiddleofthemonth.Wealsoaimtohave
trainingsessionsanddiscussionsrelatedtoalgorithms,binarysearch,technicalitieslikearraysizeandthelikes.Apartfromprovidingaplatformforprogrammingcompetitions,
CodeChefalsohasvariousalgorithmtutorialsandforumdiscussionstohelpthosewhoarenewtotheworldofcomputerprogramming.

PracticeSectionAPlacetohoneyour'ComputerProgrammingSkills'
Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+
programminglanguages.Preparingforcodingcontestswereneverthismuchfun!Receivepoints,andmoveupthroughtheCodeChefranks.Useourpracticesectiontobetterprepare
yourselfforthemultipleprogrammingchallengesthattakeplacethroughoutthemonthonCodeChef.

CompeteMonthlyProgrammingContestsandCookoffs
Hereiswhereyoucanshowoffyourcomputerprogrammingskills.Takepartinour10daylongmonthlycodingcontestandtheshorterformatCookoffcodingcontest.Putyourself
upforrecognitionandwingreatprizes.OurprogrammingcontestshaveprizesworthuptoINR20,000(forIndianCommunity),$700(forGlobalCommunity)andlotsmoreCodeChef
goodiesupforgrabs.

ProgrammingTools

PracticeProblems

Initiatives

OnlineIDE

Easy

GoforGold

UpcomingCodingContests

Medium

CodeChefforSchools

ContestHosting

Hard

CampusChapters

ProblemSetting

Challenge

CodeChefTutorials

Peer

CodeChefWiki

School
FAQ's

https://www.codechef.com/problems/COOKMACH

3/3

You might also like