1 / 11

Lynbrook Computer Science

Lynbrook Computer Science. “ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” –Tom Cargill. Last Week’s Problem. Bignum

makan
Download Presentation

Lynbrook Computer Science

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. Lynbrook Computer Science “The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” –Tom Cargill

  2. Last Week’s Problem • Bignum • Adding, subtracting, multiplying, and dividing large numbers

  3. Solution Variables: private String bigNum; privatebyte[] digits; privatebytesign; Constructor: publicBigNum( String num ) { bigNum = num;

  4. Solution (cont.) // determine if negative/positive if( bigNum.charAt( 0 ) == '-' ) { sign = -1; bigNum = bigNum.substring( 1 ); } else sign = 1; // store the digits digits = newbyte[ bigNum.length() ]; for( inti = 0; i < digits.length; i++ ) digits[i] = (byte) ( bigNum.charAt( digits.length - 1 - i ) - '0' ); }

  5. Solution (cont.) Subtraction: publicBigNum subtract( BigNum other ) { // add the opposite return add( other.swapSign() ); } Main logic behind adding and subtracting: for( inti = 0; i < maxLength - 1; i++ ) { digit = otherDigit = 0; // get the digits, if they exist if( i < length ) digit = (byte) ( sign * digits[i] );

  6. Solution (cont.) if( i < otherLength ) otherDigit = (byte) ( other.sign * other.digits[i] ); // sum of the digit and any carry result = (byte) ( digit + otherDigit + carry ); // adding if( other.sign == 1 ) { if( result >= 10 ) { carry = 1; result -= 10; } else carry = 0; }

  7. Solution (cont.) // subtracting else { // don't carry if this is the last digit if( result < 0 && i != length - 1 ) { carry = -1; result += 10; } else carry = 0; }

  8. Solution (cont.) // since we're reversing the buffer at the end, addthe negative sign after the digit value if( result < 0 ) buffer.append( -result + "-" ); else buffer.append( result ); }

  9. New Problem of the Week Denise the robot unicorn wants to bring her infamous infinitely large collection of fabulous items to school for show-and-tell. However, she can only carry a limited weight, so she wants to bring the most fabulous collection she can carry. There are many different types of fabulous items, including, but not limited to, fabulous pixies, fabulous stars, and fabulous dolphins. Each type of item has a certain level of fabulousness and a certain weight.

  10. New Problem of the Week (cont.) • Help Denise devise and implement an algorithm to determine the maximum fabulousness of the collection to bring. • Input will be read from the console, in this format: X YW1 V1W2 V2W3 V3...WY VY Where X (1 < X < 1000) is the maximum weight Denise can carry, Y (1 < Y < 1000) is the number of items (how many lines you have to read), and the W (1 < W < 1000) and V (1 < V < 9012) values are the weight and value, respectively, of each type of item. • The output (to the console) shall consist of a single number, the maximum value of the items Denise will carry.

  11. USACO Schedule • Sent out via e-mail • Check your spam • 22-25 Oct, 2010 – USACO Qualification Contest ** OPTIONAL ** • 5-8 Nov, 2010 – USACO November Contest • 3-6 Dec, 2010 – USACO December Contest • 7-10 Jan, 2011 – USACO January Contest • 4-7 Feb, 2011 – USACO February Contest • 11-14 Mar, 2011 – USACO March Contest • 28Apr-2May, 2011 – USACO US Open • Early Jun, 2011 – USA Invitational Computing Olympiad (~8                       days, by invitation), Clemson, SC • 22-29 Jul, 2011 – IOI – Pattaya, Thailand (by invitation) –> conflicts with IMO!

More Related