Sie sind auf Seite 1von 12

Introduction Who We Are The USA Computing Olympiad fosters pre-college computing through training, contests, and international

competitions. A handful of coaches organizes these features and also chaperone students who represent the USA in international venues. ind a wealth of details and other information at the USACO !e" Site. Specific USACO Goals Specific goals of the USACO include# Train USA team to win multiple gold medals at the ne$t %O%. &ngage USA students in learning and growing to achieve the first goal Conduct an eight day USA Olympiad for the "est '( USA students in order to identify the final four USA representatives for international competition.

About Advanced Training This we"site includes training for students who typically have a year or two of programming e$perience and also have interest in )algorithmic programming). The techni*ues taught and drilled here are difficult. &$pect to spend anywhere from a few minutes to several hours per problem if you are an e$cellent programmer. +eginners will not en,oy these pro"lems, as they re*uire e$tensive practice and e$perience. Someday we hope to have an additional lower-level training site for those ,ust "eginning in programming. About This Web Site This we" site is designed to accomplish the goals a"ove. %t)s password protected. All functions are availa"le -. hours/day with mechanical responses and trac0ing so anyone can learn at their own pace and with no pressure. %nstructional te$t, pro"lems, and analyses are concise 1in order to minimize time spent reading vs. programming2 Over '33 contest-style pro"lems are complemented "y almost two dozen instructional te$ts on every type of pro"lem from the programming contest domain. The pro"lems are interspersed throughout the sections "ased more on difficulty 1easier ones first2 than on 4pro"lem type4. A we"-"ased se*uencing system guides students through ever more challenging pro"lems and te$ts. 5etailed e$planations of algorithms and pro"lems in standard %O% format to familiarize competitors with international competitive environments and challenges Tas0s re*uire programs to "e su"mitted to an automatic grading system for evaluation against a "road spectrum of test cases.

The site offers *uic0 turnaround and feed"ac0 for pro"lem grading 1usually ,ust a few seconds2. Analysis pages e$plicate details of pro"lem solutions and show a well-coded and well-commented solution. arn

Awards and Privileges To

The USACO will send you certificates as you progress through this site. urthermore, outstanding participation will enhance your chances of "eing chosen for USACO training camp in 6une. Small awards will also "e given at the end of the season to those who have the fastest solutions for some of the more complicated pro"lems. !atch the we" site for the standings as they emerge. 5on)t "e fooled "y the first few pro"lems. Su"se*uent pro"lems are ever more challenging. !ow "ong #oes This Ta$e% 5ifferent people will ta0e different spans of time to move through this material, especially the '337 programming challenges. Some students already have years and years of e$perience, perhaps even at the international level. Others are ,ust "eginning to compete. Any rate much lower than one pro"lem per two wee0s is pro"a"ly not high enough to achieve a rewarding training effect. %t is anticipated some of the "est students will average one pro"lem or more per day for the first two sections 1slower after that2. To get the most out of this we" site, you should solve the pro"lems in order, understand each paragraph of the instructional te$ts, and digest the analyses to see how they apply to your solutions. eel free to improve your solution after you read the analysis. urthermore, feel free to send us new or "etter analyses if you have them. Administrivia A few items to ease your use of the site# Use the 4+ac0 to USACO 8ateway4 lin0 to o"serve updates properly Use the 4Su"mit a Comment or 9uestion4 lin0 for *uic0 communication to coaches !atch 4:&!S4 on the left column for late "rea0ing news

Submitting Solutions The USACO Training ;rogram features an automatic grading system for your homewor0 pro"lems. <ou su"mit your programs from the pro"lem page itself= they

are compiled and graded= the results are conveyed "ac0 to you -- all within a few seconds. C/C77, ;ASCA>, and 6ava are availa"le. This system uses the 8:U 8CC compilation suite for C/C77 programs and the ree ;ascal system for ;ascal programs. The 6ava compiler is g,c as this is written and is soon to "e upgraded. The grading system compilers are those often used at the %O% 1though 6ava is not used at the international championships2. These newer compilers uses ?- "it int)s= the +orland compilers use '@ "it int)s. 5O :OT 8&T %: TAOU+>& +&CAUS& O TB%SC Su"mit solutions via the we" "y typing the name of the file containing the source code into the )Su"mit a file#) "o$ at the "ottom of pro"lem description pages.. ;rogram su"missions re*uire simple !eader comments# your %5 1i.e., your USACO login name2, the name of the program 1which will "e given in each programming assignment, and the language used. See the e$amples "elow to get the idea. &very training page pro"lem has input and output. Currently, the input appears in a file named )pro"name.in) 1e.g., if the pro"lem name is )ride), then the input filename is )ride.in)2. Output must "e written to a file named )pro"name.out) 1i.e., )ride.out) for the )ride) pro"lem2.

The &irst Challenge The simplest programming challenge is named )test) and re*uires you to read a pair of small integers from a single input line in the file )test.in) and print their sum to the file )test.out). +elow is a simple solution in the )C) programming language. :ote the use of )e$it 132=), which is usually re*uired to e$it properly. /* ID: your_id_here LANG: C TASK: test */ #include <stdio.h !"in #$ % &IL' *(in ) (o*en #+test.in+, +r+$-

&IL' *(out ) (o*en #+test.out+, +.+$int ", /(sc"n( #(in, +0d 0d+, 1", 1/$(*rint( #(out, +0d3n+, "4/$e5it #6$7 +elow is a simple solution in the C77 programming language. :ote the use of )return 132=), which is usually re*uired to e$it properly. /* ID: your_id_here 89:G: test LANG: C44 */ #include <iostre"! #include <(stre"! #include <strin2 /* the t.o in*ut inte2ers */

usin2 n"!es*"ce std-

int !"in#$ % o(stre"! (out #+test.out+$i(stre"! (in #+test.in+$int ", /(in " /-

(out << "4/ << endlreturn 6-

7 +elow is a simple solution in the ;ASCA> programming language# % ID: your_id_here 89:G: test LANG: 8ASCAL 7 8ro2r"! Test;"r (in, (out: te5t", /: .ord<e2in Assi2n#(in, =test.in=$- 9eset#(in$Assi2n#(out, =test.out=$- 9e.rite#(out$9e"dln#(in, ", /$>riteln#(out, "4/$Close#(out$'nd. And here is the same program, this time in 6ADA. :ote that the program presumes the file opens will succeed, which they will# /* ID: your_id_here LANG: ?A;A TASK: test */ i!*ort @"A".io.*i!*ort @"A".util.*-

cl"ss test % *u/lic st"tic Aoid !"in #Strin2 BC "r2s$ thro.s I:'5ce*tion % // Dse <u((ered9e"der r"ther th"n 9"ndo!Access&ile- it=s !uch ("ster <u((ered9e"der ( ) ne. <u((ered9e"der#ne. &ile9e"der#+test.in+$$// in*ut (ile n"!e 2oes "/oAe 8rint>riter out ) ne. 8rint>riter#ne. <u((ered>riter#ne. &ile>riter#+test.out+$$$// Dse Strin2ToEeniFer As. re"dLine/s*lit GG lots ("ster Strin2ToEeniFer st ) ne. Strin2ToEeniFer#(.re"dLine#$$// Get line, /re"E into toEens int iH ) Inte2er.*"rseInt#st.ne5tToEen#$$int iI ) Inte2er.*"rseInt#st.ne5tToEen#$$out.*rintln#iH4iI$out.close#$(ile Syste!.e5it#6$7 7 Important' (uffered)eader and StringTo$eni*er are far more efficient than man+ other schemes for reading input, The+ can ma$e a huge difference in the efficienc+ of +our program- Use them// don=t o!it thisJ // (irst inte2er // second inte2er // out*ut result // close the out*ut

<ou can try as many different things 1su",ect to the caveats "elow2 as you li0e to see how the grading system wor0s. Theoretically, you can)t "rea0 it or crash it. %f you see a pro"lem, please let me 0now. The restrictions are few# One second runtime limit unless other specified 1E33 FBz ;entium %%%2 A"out '@F+ datasize limit A"out 'F+ stac0size limit

+e sure your program e$its with status 3 +e sure you print complete lines 1with terminating newline2, not ,ust a few words or num"ers 5on)t use files other than the specified input, output, and au$iliary files Other common sense rules that need not "e listed

The rules are simple# 5on)t try to cheat. #on.t /ust print the answers, you must calculate them in your program. %f you ,ust print answers, your login %5 might "e removed. 5on)t try to loo0 at other files on the system or use other schemes to "rea0 security 5on)t try to "rea0 common sense rules of privacy ;lease report anomalous "ehavior to me right away 1G0olstadHdelos.comI2 Bave as much fun as possi"le &arn a trip to the %O% and other e$otic contestsC

Some hints# +oth stderr and stdout are returned to you when errors occur eel free to as0 *uestions and send in comments <our reported output has JK)s su"stituted for spaces %nclude this comment if you use try/catch/throw in C77# /Lpragma handlee$ceptionsL/

Compiler comments 1please send in new compiler comments as you find them2# !e)re using g77 1a.0.a. d,gpp on ;Cs2, ree ;ascal, and g,c %n C/C77, ints are ?- "its 1char is M= short is '@= long is ?-= long long is @.2 some li"raries have new names= some have different or missing functions stricmp doesn)t e$ist= use strcmp for string compares strrev does not e$ist neither itoa nor ltoa e$ists 1use sprintf instead2 :o need for huge declarations - pointers already go everywhere ;ascal users# "e sure to 4close4 your output file or the output might not appear

8ive it a tryC Su"mit one of the programs a"ove, using your own %5. Fouse it off into a file then type in the name of the te$t file that contains the source# 0our )ide Is !ere %t is a well-0nown fact that "ehind every good comet is a U O. These U Os often come to collect loyal supporters from here on &arth. Unfortunately, they only have room to pic0 up one group of followers on each trip. They do, however, let the groups 0now ahead of time which will "e pic0ed up for each comet "y a clever scheme# they pic0 a name for the comet which, along with the name of the group, can "e used to determine if it is a particular group)s turn to go 1who do you thin0 names the cometsN2. The details of the matching scheme are given "elow= your ,o"

is to write a program which ta0es the names of a group and a comet and then determines whether the group should go with the U O "ehind that comet. +oth the name of the group and the name of the comet are converted into a num"er in the following manner# the final num"er is ,ust the product of all the letters in the name, where 4A4 is ' and 4O4 is -@. or instance, the group 4USACO4 would "e -' L 'P L ' L ? L '( Q 'EP((. %f the group)s num"er mod .E is the same as the comet)s num"er mod .E, then you need to tell the group to get readyC 1Aemem"er that 4a mod "4 is the remainder left over after dividing a "y "= ?. mod '3 is ..2 !rite a program which reads in the name of the comet and the name of the group and figures out whether according to the a"ove scheme the names are a match, printing 48O4 if they match and 4STA<4 if not. The names of the groups and the comets will "e a string of capital letters with no spaces or punctuation, up to @ characters long. &$amples# %nput Output

C:K'TL G: M;NGAT A<STA9 STAN DSAC: P)OG)A1 2A1 ' ride I2PUT &O)1AT >ine '# An upper case character string of length '..@ that is the name of the comet. >ine -# An upper case character string of length '..@ that is the name of the group. 2OT # The input file has a newline at the end of each line "ut does not have a 4return4. Sometimes, programmers code for the !indows paradigm of 4return4 followed "y 4newline4= don)t do thatC Use simple input routines li0e 4readln4 1for ;ascal2 and, for C/C77, 4fscanf4 and 4fidIIstring4. SA1P" COF&T9 BD:8AT OUTPUT &O)1AT A single line containing either the word 48O4 or the word 4STA<4. SA1P" 8O OUTPUT 3file ride,out4 I2PUT 3file ride,in4

Programming Contest Problem T+pes Bal +urch conducted an analysis over spring "rea0 of 'PPP and made an amazing discovery# there are only '@ types of programming contest pro"lemsC urthermore, the top several comprise almost M3R of the pro"lems seen at the %O%. Bere they are# 5ynamic ;rogramming 8reedy Complete Search lood ill Shortest ;ath Aecursive Search Techni*ues Finimum Spanning Tree Snapsac0 Computational 8eometry :etwor0 low &ulerian ;ath Two-5imensional Conve$ Bull +ig:ums Beuristic Search Appro$imate Search Ad Boc ;ro"lems

The most challenging pro"lems are Com"ination ;ro"lems which involve a loop 1com"inations, su"sets, etc.2 around one of the a"ove algorithms - or even a loop of one algorithm with another inside it. These seem e$traordinarily tric0y to get right, even though conceptually they are JJo"vious)). %f you can master solving ,ust .3R of these pro"lem types, you can almost guarantee a silver medal at the %O%. Fastering M3R moves you into the gold range almost for sure. Of course, Jmastery) is a tough nut to crac0C !e)ll "e supplying a plethora of pro"lems so that you can hone your s0ills in the *uest for international fame. Ad !oc Problems JAd hoc) pro"lems are those whose algorithms do not fall into standard categories with well-studied solutions. &ach ad hoc pro"lem is different= no specific or general techni*ues e$ist to solve them. Of course, this ma0es the pro"lems the Jfun) ones, since each one presents a new challenge. The solutions might re*uire a novel data structure or an unusual set of loops or conditionals. Sometimes they re*uire special com"inations that are rare or at least rarely encountered. Ad hoc pro"lems usually re*uire careful reading and usually yield to an attac0 that revolves around carefully se*uencing the instructions given in the pro"lem.

Ad hoc pro"lems can still re*uire reasona"le optimizations and at least a degree of analysis that ena"les one to avoid loops nested five deep, for e$ample. Fore ad hoc pro"lems appear on this we" site than any other 0ind of pro"lem. Always "e ready for an ad hoc pro"lem if you can not classify a pro"lem as one of the other standard types 1to "e listed later2.

Greedy Gift Givers


A group of NP (2 NP 10) uniquely named friends has decided to exchange gifts of money. ach of these friends might or might not gi!e some money to any or all of the other friends. "i#e$ise% each friend might or might not recei!e money from any or all of the other friends. &our goal in this pro'lem is to deduce ho$ much more money each person gi!es than they recei!e. (he rules for gift)gi!ing are potentially different than you might expect. ach person sets aside a certain amount of money to gi!e and di!ides this money e!enly among all those to $hom he or she is gi!ing a gift. No fractional money is a!aila'le% so di!iding * among 2 friends $ould 'e 1 each for the friends $ith 1 left o!er )) that 1 left o!er stays in the gi!er+s ,account,. -n any group of friends% some people are more gi!ing than others (or at least may ha!e more acquaintances) and some people ha!e more money than others. .i!en a group of friends% no one of $hom has a name longer than 1/ characters% the money each person in the group spends on gifts% and a (su')list of friends to $hom each person gi!es gifts% determine ho$ much more (or less) each person in the group gi!es than they recei!e.

IMPORTANT NOTE
(he grader machine is a "inux machine that uses standard 0nix con!entions1 end of line is a single character often #no$n as +2n+. (his differs from 3indo$s% $hich ends lines $ith t$o charcters% +2n+ and +2r+. 4o not let your program get trapped 'y this5

PROGRAM NAME: gift1 INPUT FORMAT


"ine 11 (he single integer% NP "ines 2..NP611 ach line contains the name of a group mem'er "ines NP62..end1 NP groups of lines organi7ed li#e this1 (he first line in the group tells the person+s name $ho $ill 'e gi!ing gifts. (he second line in the group contains t$o num'ers1 (he initial amount of money (in the range 0..2000) to 'e di!ided up into gifts 'y the gi!er

and then the num'er of people to $hom the gi!er $ill gi!e gifts% N.i (0 N.i NP)1). -f N.i is non7ero% each of the next N.i lines lists the the name of a recipient of a gift.

SAMPLE INPUT (file gift1.in)


O d"Ae l"ur" o.en AicE "!r d"Ae I66 P l"ur" o.en AicE o.en O66 H d"Ae "!r HO6 I AicE o.en l"ur" 6 I "!r AicE AicE 6 6

OUTPUT FORMAT
(he output is NP lines% each $ith the name of a person follo$ed 'y a single 'lan# follo$ed 'y the net gain or loss (final8money8!alue ) initial8money8!alue) for that person. (he names should 'e printed in the same order they appear on line 2 of the input. All gifts are integers. ach person gi!es the same integer amount of money to each friend to $hom any money is gi!en% and gi!es as much as possi'le that meets this constraint. Any money not gi!en is #ept 'y the gi!er.

SAMPLE OUTPUT (file gift1.out)


d"Ae P6I l"ur" QQ o.en GPOR AicE HSH "!r GHO6

Das könnte Ihnen auch gefallen