1 / 17

Solving Problems Quickly

Solving Problems Quickly. UAkron Programming Team January 20, 2012. Part 1 Rules. Teams of 1 . One problem per round. This is about getting a correct solution QUICKLY! But it still has to execute in the time allowed. Problem will be revealed on the board.

hidi
Télécharger la présentation

Solving Problems Quickly

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Solving Problems Quickly UAkron Programming Team January 20, 2012

  2. Part 1 Rules • Teams of 1. One problem per round. • This is about getting a correct solution QUICKLY! • But it still has to execute in the time allowed. • Problem will be revealed on the board. • Entire specification will be on one slide. • The spec will be less verbose than typical problems. • You get ONE SUBMIT (if your first submit is wrong, keep working, but the 20 minute penalty will likely be insurmountable) • The command to run the program should be typed into the console but not executed. • THEN raise your hand (or otherwise get my attention if I’m distracted). I will come over and test it. • First correct answer wins.

  3. Part 1 Hints • Do the minimum amount of work necessary to get a correct solution that runs within time. • Double check your output formatting (you only get one submit). • Quickly try at least a couple non-sample input cases and edge cases (0/1/many, upper bounds, halting conditions, etc.)

  4. Ready?

  5. 1. Generalized Euler 1 • If we list all the natural numbers below 11 that are multiples of 3 or 5, we get 3, 5, 6, 9 and 10. The sum of these multiples is 33. • Each line will contain three positive integers nab, with n < 100002, a< 10000 and b < 10000. Find the sum of all the multiples of aor bbelow n. Stop when n = a = b = 0. The sum will be less than 231. • Sample Input Sample Output11 3 5 330 0 0

  6. Example code • Scanner scan = new Scanner(System.in);while(true){int n = scan.nextInt(); if(n == 0) return;int a = scan.nextInt();int b = scan.nextInt();int sum = 0; // O(n) is good enough when n is this small. for(inti = 1; i < n; i++) if(i % a == 0 || i % b == 0) sum += i;System.out.println(sum);}

  7. 2. Pr1m41 F34r • Leet speak is silly, but here’s a problem about it anyway. You’ll be given a string containing only alphabetic characters and spaces. Convert the following letters to digits:E, e 3 L, l  1 T, t  7 S, s  5A, a  4 I, i  1 O, o  0 G, g  9 • Any spaces and letters that were not converted to digits should be discarded, the digits should be concatenated into one positive integer n with 1 < n < 1000000 (guaranteed). • If n is prime, print: “Pr1m41 F34r”. If n is composite, print “This problem is silly.” An input string of “Make it stop” indicates the end of input and should not be processed. • Sample Input Sample OutputPrimal Fear This problem is silly.Rabble This problem is silly.Fried Crud Pr1m41 F34rMake it stop

  8. Example code • Since we only need to check one integer for primalityper input case, don’t waste time making the prime check too efficient. The following is definitely fast enough:booleanisPrime(int n){ for(inti = 2; i <= Math.sqrt(n); i++) { if(n % i == 0) return false; } return true;}

  9. 3. More Generalized Euler 1 • If we list all the natural numbers below 11 that are multiples of 3 or 5, we get 3, 5, 6, 9 and 10. The sum of these multiples is 33. • Each line will contain three positive integers nab, with 100,000 < {n, a, b}< 2,000,000,002. Find the sum of all the multiples of a or b below n. Stop when n = a = b = 0. The sum will be less than 263. • Sample Input Sample Output100002 100001 100001 1000010 0 0

  10. Notes • O(n) isn’t good enough when n is 2 billion. • Try 2000000000 222222 333333 • Instead, increment through <a, 2a, 3a, 4a, …> while k*a is less than n, summing as you go. Then do the same for <b, 2b, 3b, 4b, …> and sum as you go unless the term k*b is also divisible by a (in which case it’s already been counted). • This is O(n/a) + O(n/b), and in the worst case 2000000000 / 100000 = 20000 iterations. • There’s also a O(1) solution to this problem. Can you find it?

  11. 4. Anagrams • Given two strings, determine if they are anagrams, meaning that one string can be created by rearranging the letters in the other (ignoring casing and spaces in our case). When the two strings are both exactly “Quit”, this indicates the end of input and should not be processed. • Sample Input Sample OutputSpecial YesAce Slip YesRadar Tea Quill NoQuadrilateralStopStoopQuitQuit

  12. Part 2 Rules • Teams of 2. • This is about getting TWO correct solutions QUICKLY! • But they still have to execute in the time allowed. • Problems will be handed out. • Name your source files: <teamname>_<problem>.<extension> • You get multiple submits. • Copy solutiuons to: /home/grad/dpoeschl/2012spring/week1

  13. Part 2 Hints • The order in which you solve the problems might matter (but it might not) • Teamwork, teamwork, teamwork. • All the hints from part 1 • Do the minimum amount of work necessary to get 2 correct solutions that run within time. • Double check your output formatting, you only get one submit. • Quickly try at least a couple non-sample input cases.

  14. Ready? • Take a few minutes to discuss strategy.

  15. Round 1 • Bank Robbin (B-W 2011) • Tower of Defense (B-W 2011) • (See Resources slide for links to these problems)

  16. Ran out of time… more next week.

  17. Resources • B-W Contest • http://contest.acm.bw.edu/contest/problems/

More Related