32
BEGINNER CHEF AND LUCKY NUMBER Mr. Chef has been given a number N. He has a tendency to double whatever he get. So now he has got the number N with him and he has multiplied the number N by 2. Now Chef is superstitious. He believes in something known as Lucky Number. His lucky number is defined as any number, which when multiplied by 2 has no other factors other than 1, 2, and N. If the number is lucky all you have to do is print “LUCKY NUMBER”. If the number is not a lucky number, print “Sorry”.. Input The first line consists of T, which is the number of test cases. Every line of the next T lines consists of N. Output Print LUCKY NUMBER if the number is lucky and “Sorry” if the number is not lucky followed by a new line. Constraints 1<=T<=1000 1<=N<=1000000 Input 3 26 12 11 Output: Sorry Sorry LUCKY NUMBER CHEF AND WAY After visiting a childhood friend, Chef wants to get back to his home. Friend lives at the first street, and Chef himself lives at the N-th (and the last) street. Their city is a bit special: you can move from the X-th street to the Y-th street if and only if 1 <= Y - X <= K, where K is the integer value that is given to you. Chef wants to get to home in such a way that the product of all the visited streets' special numbers is minimal (including the

c# Problems

Embed Size (px)

DESCRIPTION

C# problems for practice

Citation preview

BEGINNER CHEF AND LUCKY NUMBERMr. Chef has been given a number N. He has a en!en"# $ !$ub%e &haever he ge. '$ n$& he has g$ he number N &ih him an! he has mu%i(%ie! he number N b# ). N$& Chef is su(ersii$us. He be%ieves in s$mehing *n$&n as Lucky Number. His %u"*# number is !efine! as an# number+ &hi"h&hen mu%i(%ie! b# ) has n$ $her fa"$rs $her han ,+ )+ an! N. If he number is %u"*# a%% #$u have $ !$ is (rin LUCKY NUMBER. If he number is n$ a %u"*# number+ (rin Sorry..Input-he firs %ine "$nsiss $f -+ &hi"h is he number $f es "ases. Ever# %ine $f he ne. - %ines "$nsiss $f N.Output/rin LUCKY NUMBER if he number is %u"*# an! 0'$rr#1 if he number is n$ %u"*# f$%%$&e!b# a ne& %ine.Constrants,23-23,444 ,23N23,444444Input5)6,) ,,Output!'$rr#'$rr#LUCKY NUMBERCHEF AND 7AY Afer visiing a "hi%!h$$! frien!+ Chef &ans $ ge ba"* $ his h$me. Frien! %ives a he firs sree+ an! Chef himse%f %ives a he N8h 9an! he %as: sree. -heir "i# is a bi s(e"ia%; #$u "an m$ve fr$m he "8h sree $ he Y8h sree if an! $n%# if , 23 Y 8 " 23 K+ &here K is he ineger va%ue ha is given $ #$u. Chef &ans $ ge $ h$me in su"h a &a# ha he (r$!u" $f a%% he visie! srees< s(e"ia% numbers is minima% 9in"%u!ing he firs an! he N8h sree:. /%ease+ he%( him $ fin! su"h a (r$!u".Input-he firs %ine $f in(u "$nsiss $f &$ ineger numbers 8 N an! K 8 he number $f srees an! he va%ue $fK res(e"ive%#. -he se"$n! %ine "$nsis $f N numbers 8 #$+ #%+ ...+ #N res(e"ive%#+ &here # e=ua%s $ he s(e"ia% number $f he 8h sree.Output/%ease $u(u he va%ue $f he minima% ($ssib%e (r$!u"+ m$!u%$ $&&&&&&&&'.Constrants$ > N > $&()$ > # > $&()$ > K > NE*amp+eInput!? ), ) 5 ?.Output!@GREGAIAN CALENDARA""$r!ing $ Greg$rian Ca%en!ar+ i &as M$n!a# $n he !ae 4,B4,B)44,. If an# #ear is in(u+ 7rie a (r$gram $ !is(%a# &ha is he !a# $n he ,s Canuar# $f his #ear.Input-he firs %ine "$nains an ineger ,+ $a% number $f es"ases. -hen f$%%$& , %ines+ ea"h %ine "$nains an ineger year.OutputDis(%a# he !a# $n he ,s Canuar# $f ha #ear in %$&er"ase %eer.Constrants, - , - ,444,D44- #.B.C -)E44E*amp+eInput5 ,DD?,DD,)4,?Outputsaur!a#ues!a#&e!nes!a# CHEF AND HI' 'EFUENCE Chef has a se=uen"e $f N numbers. He %i*e a se=uen"e beer if he se=uen"e "$nains his fav$rie se=uen"e as a subsring.Given he se=uen"e an! his fav$rie se=uen"e9F: "he"* &heher he fav$rie se=uen"e is "$naine! in he se=uen"eIn(u-he firs %ine &i%% "$nain he number $f es "ases an! are f$%%$&e! b# he "ases. Ea"h es "ase "$nsiss $f f$ur %ines; -he %engh $f he se=uen"e+ he se=uen"e N+he %engh $f F an! he se=uen"e FAu(u/rin GYesG if he se=uen"e "$nains he fav$urie se=uen"e in i $her&ise (rin GN$GC$nsrains,23-23,4 , ,Input!)6, ) 5 ? E 65) 5 ?6)) E 6 55 , ?)? ,EOutput!YesN$CHEF AND DALL' Chef is fan $f (airs an! he %i*es a%% hings ha "$me in (airs. He even has a !$%% "$%%e"i$n in &hi"h a%% !$%%s have (aire!.Ane !a# &hi%e g$ing hr$ugh his "$%%e"i$n he f$un! ha here are $!! number $f !$%%s. '$me$ne ha! s$%en a !$%%HHHHe%( "hef fin! &hi"h #(e $f !$%% is missing..Input-he firs %ine "$nains he number $f es "ases. 'e"$n! %ine $f he in(u "$nains he number $f e%emens in he arra#. -he ne. n %ines are he #(es $f ea"h !$%% ha is %ef.OutputFin! he #(e $f !$%% ha !$esn< have a (airConstrants,23-23,4 ,23N23,44444 9,4IE: ,23i23,44444Input!,5, ),Output!)Input!,E,,))5Output!5FARMER AND HI' /LA- 'an$sh has a farm a B#e%an!. He has a ver# big fami%# $ %$$* afer. His %ife a*es a su!!en urn an! he runs in$ a finan"ia% "risis. Afer giving a%% he m$ne# he has in his han!+ he !e"i!es $ se%% s$me (ars $f his (%$s. -he s(e"ia%# $f his (%$ is ha i is re"angu%ar in naure. 'an$sh "$mes $ *n$& ha he &i%% ge m$re m$ne# if he se%%s s=uare sha(e! (%$s. '$ *ee(ing his in min!+ he !e"i!es $ !ivi!e his (%$ in$ minimum ($ssib%e s=uare (%$s s$ ha he "an ge ma.imum (r$fi $u $f his.'$ #$ur as* is $ fin! he minimum number $f s=uare (%$s ha "an be f$rme! $u $f he re"angu%ar (%$.Input-he in(u "$nsiss $f - number $f es "ases. - %ines f$%%$&. Ea"h %ine "$nsiss $f &$ inegers N an! M &hi"h !en$es he %engh an! brea!h $f he re"ang%e.OutputAu(u is a sing%e %ine &hi"h !en$es he minimum number $f s=uare (%$s ha "an be f$rme!Constrants,23-23)4 ,23M23,4444 ,23N23,4444Input!),4 ,E? 6Output!66GRADE -HE '-EEL A "erain gra!e $f see% is gra!e! a""$r!ing $ he f$%%$&ing "$n!ii$ns.Har!ness mus be greaer han E4. Carb$n "$nen mus be %ess han 4.J. -ensi%e srengh mus be greaer han E644. -he gra!es are as f$%%$&s;Gra!e is ,4 if a%% hree "$n!ii$ns are me. Gra!e is D if "$n!ii$ns 9i: an! 9ii: are me. Gra!e is @ if "$n!ii$ns 9ii: an! 9iii: are me. Gra!e is J if "$n!ii$ns 9i: an! 9iii: are me. Gar!e is 6 if $n%# $ne "$n!ii$n is me. Gra!e is E if n$ne $f hree "$n!ii$ns are me. 7rie a (r$gram+ if he user gives va%ues $f har!ness+ "arb$n "$nen an! ensi%e srengh $f he see% un!er "$nsi!erai$n an! !is(%a# he gra!e $f he see%.Input -he firs %ine "$nains an ineger ,+ $a% number $f es"ases. -hen f$%%$& , %ines+ ea"h %ine "$nains hree numbers /ar0ness+ carbon content an! tens+e stren1t/ $f he see%.Output /rin Gra!e $f he see% !e(en!ing $n C$n!ii$ns.Constrants , - , - ,444,- /ar0ness. carbon content. tens+e stren1t/ - ,4444E*amp+eInput5 E5 4.6 E64)?E 4 ?E444 4 4 Output,466'MALLE'- NUMBER' AF NA-E' C$nsi!er a "urren"# s#sem in &hi"h here are n$es $f seven !en$minai$ns+ name%#+ Rs. ,+ Rs. )+ Rs. E+ Rs. ,4+ Rs. E4+ Rs. ,44.If he sum $f Rs. N is in(u+ &rie a (r$gram $ "$m(uer sma%%es number $f n$es ha &i%% "$mbine $ give Rs. N.Input-he firs %ine "$nains an ineger ,+ $a% number $f es"ases. -hen f$%%$& , %ines+ ea"h %ine "$nains an ineger N.OutputDis(%a# he sma%%es number $f n$es ha &i%% "$mbine $ give N.Constrants, - , - ,444, - N - ,444444E*amp+eInput5 ,)44E44)?)Output,)EJnt notes23 4 5$&&. )&. $&. ). %. $678or 9 4 &7: ; 58 9notes23 :4 n> 5s =4 n ? notes237n 4 n @ notes237CHEF AND -7A '-RING' Chef has f$un! &$ ver# $%! shees $f (a(er+ ea"h $f &hi"h $rigina%%# "$naine! a sring $f %$&er"ase Lain %eers. -he srings $n b$h he shees have e=ua% %enghs. H$&ever+ sin"e he shees are ver# $%!+ s$me %eers have be"$me unrea!ab%e.Chef &$u%! %i*e $ esimae he difference be&een hese srings. Le>>< are va%i! (arenheses se=uen"es+ bu 9>9< an! < are n$.Mi*e has a va%i! (arenheses se=uen"e. He rea%%# %i*es ever#hing ab$u his se=uen"e+ e."e( he fa" ha i is =uie %$ng. '$ Mi*e has re"en%# !e"i!e! ha he &i%% re(%a"e his (arenheses se=uen"e &ih a ne& $ne in he near fuure. Bu n$ ever# va%i! (arenheses se=uen"e &i%% saisf#him. -$ he%( #$u un!ersan! his re=uiremens &e ,+444 in!i"aing ha &$ rans"eivers "an "$mmuni"ae !ire"%# &ih$u an inerme!iae rans"eiver if he# are a m$s R meers a&a# fr$m ea"h $her. -he remaining hree %ines $f he es "ase !es"ribe he "urren %$"ai$ns $f he Chef+ he hea! server+ an! he s$us8"hef+ res(e"ive%#. Ea"h su"h %ine "$nains &$ inegers Z+Y 9a m$s ,4+444 in abs$%ue va%ue: in!i"aing ha he res(e"ive (ers$n is %$"ae! a ($sii$n Z+Y.Au(uF$r ea"h es "ase #$u are $ $u(u a sing%e %ine "$naining a sing%e sring. If i is ($ssib%e f$r a%% hree $ "$mmuni"ae hen #$u sh$u%! $u(u G#esG. Aher&ise+ #$u sh$u%! $u(u Gn$G.-$ be "%ear+ &e sa# ha &$ rans"eivers are "%$se en$ugh $ "$mmuni"ae !ire"%# if he %engh $f he sraigh %ine "$nne"ing heir Z+Y "$$r!inaes is a m$s R.E.am(%eInput!5,4 ,4 4, 4)4 ,4 4, 4)4 44 )) ,Output!#es#esn$CHEF AND REMI''NE'' Chef is n$& a "$r($rae (ers$n. He has $ aen! $ffi"e regu%ar%#. Bu "hef !$es n$ &an $ g$ $$ffi"e+ raher he &ans $ sa# h$me an! !is"$ver !ifferen re"i(es an! "$$* hem.In he $ffi"e &here "hef &$r*s+ has &$ guar!s &h$ "$un h$& man# imes a (ers$n eners in$ he $ffi"e bui%!ing. -h$ugh he !u# $f a guar! is )? h$ur in a !a#+ bu s$meimes he# fa%% as%ee(!uring heir !u# an! "$u%! n$ ra"* he enr# $f a (ers$n in he $ffi"e bui%!ing. Bu $ne beer hing is ha he# never fa%% as%ee( a he same ime. A %eas $ne $f hem remains a&a*e an! "$uns &h$ eners in$ he $ffi"e.N$& b$ss $f Chef &ans $ "a%"u%ae h$& man# imes Chef has enere! in$ he bui%!ing. He as*e! $ he guar! an! he# give him &$ inegers # an! B+ "$un $f firs guar! an! se"$n! guar!res(e"ive%#.He%( he b$ss $ "$un he minimum an! ma.imum number $f imes Chef "$u%! have enere! in$ he $ffi"e bui%!ing.Input-he firs %ine $f he in(u "$nains an ineger , !en$ing he number $f es "ases. -he !es"ri(i$n $f he , es "ases f$%%$&s.Ea"h es "ase "$nsiss $f a %ine "$naining &$ s(a"e se(arae! inegers # an! B.OutputF$r ea"h es "ase+ $u(u a sing%e %ine "$naining &$ s(a"e se(arae! inegers+ he minimum an!ma.imum number $f imes Chef "$u%! have enere! in$ he $ffi"e bui%!ing.Constrants$ > , > $&&& > #. B > $&&&&&&E*amp+eInput!,,D ,JOutput!,D 56SN#LE #NO L#OOER /r$fess$r 'na(e has %$s $f ($i$ns. B$%es "$naining a%% #(es $f ($i$ns are sa"*e! $n she%ves&hi"h "$ver he enire &a%% fr$m f%$$r $ "ei%ing. /r$fess$r 'na(e has br$*en his b$nes severa% imes &hi%e "%imbing he $( she%f f$r rerieving a ($i$n. He !e"i!e! $ ge a %a!!er f$r him. Buhe has n$ ime $ visi Diag$n A%%e#. '$ he insru"e! R$n 7eas%e# $ ma*e a %a!!er f$r him. /r$fess$r 'na(e s(e"ifi"a%%# &ans a se( %a!!er &hi"h %$$*s %i*e an invere! , > ,444, > B 2 LS > ,444E*amp+eMIN4IG9B:L>JPSQR,9L%JB%> IG9BPL>JPSQR,9B%JL%>JPELSEJPBInput!M#"4SQR,9B%=L%>5? E,4 ,),4 )4Output!5.4 6.?45,)6.655)E ,E.6)4E,J.5)4E )).564JCU--ING RECI/E' -he "hef has a re"i(e he &ishes $ use f$r his guess+bu he re"i(e &i%% ma*e far m$re f$$! han he "an serve $ he guess.-he "hef heref$re &$u%! %i*e $ ma*e a re!u"e! versi$n $f he re"i(e &hi"h has he same rai$s $f ingre!iens+ bu ma*es %ess f$$!.-he "hef+ h$&ever+ !$es n$ %i*e fra"i$ns.-he $rigina% re"i(e "$nains $n%# &h$%e numbers $f ingre!iens+an! he "hef &ans he re!u"e! re"i(e $ $n%# "$nain &h$%e numbers $f ingre!iens as &e%%.He%( he "hef !eermine h$& mu"h $f ea"h ingre!ien $ use in $r!er $ ma*e as %i%e f$$! as ($ssib%e.In(uIn(u &i%% begin &ih an ineger -+ he number $f es "ases.Ea"h es "ase "$nsiss $f a sing%e %ine.-he %ine begins &ih a ($siive ineger N+ he number $f ingre!iens.N inegers f$%%$&+ ea"h in!i"aing he =uani# $f a (ari"u%ar ingre!ien ha is use!.Au(uF$r ea"h es "ase+ $u(u e.a"%# N s(a"e8se(arae! inegers $n a %ine+giving he =uani# $f ea"h ingre!ien ha he "hef sh$u%! use in $r!er $ ma*e as %i%e f$$! as ($ssib%e.'am(%e In(u5) ? ?5 ) 5 ?? 5 ,E D 6'am(%e Au(u, ,) 5 ?, E 5 )C$nsrains->,44)>N>E4A%% ingre!ien =uaniies are be&een , an! ,444+ in"%usive.Cie% an! Re"ei( -$m#a is a gir%. 'he %$ves Chef Cie% ver# mu"h.-$m#a %i*e a ($siive ineger p+ an! n$& she &ans $ ge a re"ei( $f Cie% , > E, > p > ,44444 9,4E:-here e.iss "$mbinai$ns $f menus &h$se $a% (ri"e is e.a"%# p.Samp+e Input?,4)E6)EE?4D6Samp+e Output),@)E*p+anatonsIn he firs sam(%e+ e.am(%es $f he menus &h$se $a% (ri"e is ,4 are he f$%%$&ing;,U,U,U,U,U,U,U,U,U, 3 ,4 9,4 menus:,U,U,U,U,U,U,U,U) 3 ,4 9D menus:)U)U)U)U) 3 ,4 9E menus:)U?U? 3 ,4 95 menus:)U@ 3 ,4 9) menus:Here he minimum number $f menus is ).In he %as sam(%e+ he $(ima% &a# is )4?@U)4?@3?4D6 9) menus:.N$e ha here is n$ menu &h$se (ri"e is ?4D6.-RAN'FARM -HE EZ/RE''IANReverse /$%ish N$ai$n 9R/N: is a mahemai"a% n$ai$n &here ever# $(era$r f$%%$&s a%% $f is$(eran!s. F$r insan"e+ $ a!! hree an! f$ur+ $ne &$u%! &rie G5 ? UG raher han G5 U ?G. If here are mu%i(%e $(erai$ns+ he $(era$r is given imme!iae%# afer is se"$n! $(eran!V s$ he e.(ressi$n &rien G5 [ ? U EG &$u%! be &rien G5 ? [ E UG firs subra" ? fr$m 5+ hen a!! E $ ha.-ransf$rm he a%gebrai" e.(ressi$n &ih bra"*es in$ R/N f$rm.Y$u "an assume ha f$r he es "ases be%$& $n%# sing%e %eers &i%% be use!+ bra"*es ST &i%% n$ be use! an! ea"h e.(ressi$n has $n%# $ne R/N f$rm 9n$ e.(ressi$ns %i*e a\b\":In(u-he firs %ine "$nains + he number $f es "ases 9%ess hen ,44:.F$%%$&e! b#%ines+ "$naining an e.(ressi$n $ be rans%ae! $ R/N f$rm+ &here he %engh $f he e.(ressi$n is %ess hen ?44.Au(u-he expressions in R/N f$rm+ $ne (er %ine.E.am(%eIn(u;59aU9b\"::99aUb:\9NU.::99aU:\99bU9aU"::I9"U!:::Au(u;ab"\UabUN.U\aUba"UU"!UI\/a"*aging Cu("a*es N$& ha Chef has finishe! ba*ing an! fr$sing his "u("a*es+ i