CS 60 Slides - PowerPoint PPT Presentation

About This Presentation
Title:

CS 60 Slides

Description:

Welcome to Programming Practicum Victorville, for DARPA's Urban Granc Challenge Pittsburgh Putting the C into CS University of St. Petersburg – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 38
Provided by: Kel7163
Learn more at: https://www.cs.hmc.edu
Category:

less

Transcript and Presenter's Notes

Title: CS 60 Slides


1
Driving N on the Dalton Highway (though it feels
like it!)
Welcome to Programming Practicum
Victorville, for DARPA's Urban Granc Challenge
Pittsburgh
Putting the C into CS
University of St. Petersburg
Waiting for the snow enveloping you on Route 5 N
to melt
Engineering dept.
exploring martian soil
On the 405, in traffic, being chased by police
(and TV) helicopters.
You arent here
Worldcom Headquarters
Krispy Kremes drive through
writing clinic reports
rebooting knuth (or turing or)
coding chunky strings
Being dragged off-course 18 miles into a marathon
race by a crazed spectator
clinic liaison phone call
installing Debian 3.1
Teaching Honors English for Janice Barbee at
Pomona High School
Leading a Gray Davis / Gary Coleman / Arnold
T-800 Schwarzenegger gubernatorial fundraiser
Massey University Palmerston North, NZ
Mailing something at the Claremont Post Office
the dumpster
2
What is this course about?
3
What is this course about?
  • A chance to improve your programming skills

Algorithm analysis and insight
What
Program design and implementation
4
What is this course about?
  • A chance to improve your programming skills

Algorithm analysis and insight
optimizing coding time
What
Program design and implementation
5
What is this course about?
  • A chance to improve your programming skills

Algorithm analysis and insight
optimizing coding time
What
Program design and implementation
ACM programming contest
Hands-on practice with algorithms and techniques
Why
Familiarity with Cs STL or Javas API (more
options in the spring)
Research/prototype programming
6
What is this course about?
  • A chance to improve your programming skills

Algorithm analysis and insight
optimizing coding time
What
Program design and implementation
ACM programming contest
Hands-on practice with algorithms and techniques
Why
Familiarity with Cs STL or Javas API (more
options in the spring)
Research/prototype programming
Unofficial course name CS -70
7
2006 ACM Results
http//socalcontest.acm.org/
Site for the regionals
http//icpc.baylor.edu/icpc/
Site for the world finals
8
Class Organization
Feedback from prior semesters
  • lab sessions not considered best use of time
  • more contest-like practice sessions
  • there should be opportunities to start coding
    cold
  • better to have the course graded individually
  • continue to play jotto
  • have better snacks lt-- need more feedback here

9
Course Organization
Sep 4 Welcome! (topic dynamic
programming) Sep 11 Practice session to work on
problems (here - laptops?) Sep 18 Discussion
session (topic graph algorithms) Sep 25
Practice session (here) Oct 2 Discussion
session (topic search problems) Oct 9 Practice
session (here) Oct 16 Discussion session
(topic geometry/parsing) Oct 23 No class -
Fall break Oct 30 Mock ACM contest, 9pm 1am,
teams of 3, in CS labs Nov 6 Brief meeting for
the ACM contest participants Nov 10 Regional
ACM contest in Riverside Nov 13 Wrap-up session
for everyone
10
Problems and grades
alternating format
lab sessions
discussion sessions
  • problem and program analysis
  • strategy, coding tips
  • 3 problems, count individually
  • 3 problems can be done by team or individually
    -- you decide
  • meet here in this room (?) - bring a laptop -
    I'll have some too.
  • contest conditions
  • new problems
  • one computer per team
  • credit for the entire team

Problems can be done any time during the term.
Problems solved during the lab sessions count as
2 problems before 6pm
11
Course webpage
reference links
problem statements and example I/O
people
results!!
administrative info
12
Grading
CS 189 is graded individually... (its possible
to take it P/F, too)
Coding Guidelines
  • problems can be done any time during the
    semester
  • discussion of algorithms always OK
  • coding should be within teams
  • during lab "contests", you may only use C or
    Java API references
  • anyother time, you may use any reference at all
    except an existing solution or partial solution
  • use /cs/ACM/acmSubmit ltfilegt to submit
  • try things out !

the reason for ACM!
13
Java !
Not required (C is the alternative), but
consider...
  • extensive library of data structures and
    algorithms available
  • I/O made simpler with 1.5s Scanner and printf

formatted output
parsed input
the C in CS!
14
Problem Set 1 Dynamic Programming
15
Problem Set 1 Dynamic Programming
Rob Gonsalves
www.sapergalleries.com/Gonsalves.html
16
Problem Set 1 multiple.java
2 6 3 19 0
Input
0 marks the end of the input
integers (N) with 2 lt N lt 10000
change!
17
Problem Set 1 multiple.java
2 6 3 19 0
Input
0 marks the end of the input
integers (N) with 2 lt N lt 10000
change!
Output
10 1110 111 11001
change!
the smallest (decimal) multiple of N with only
the digits 0 and 1 !
18
Problem Set 1 multiple.java
2 6 3 19 0
Input
0 marks the end of the input
Ideas?
Most naïve solution
integers (N) with 2 lt N lt 10000
change!
how can we save time?
Output
10 1110 111 11001
change!
the smallest (decimal) multiple of N with only
the digits 0 and 1 !
19
Dynamic programming
Storing intermediate results in a table for fast
look-up
multiple.java
input N 6
possible remainders upon dividing by N (6)
0
1
2
3
4
5




1
2
of digits in answer
3
4
20
Dynamic programming
Storing intermediate results in a table for fast
look-up
input N 6
possible remainders upon dividing by N (6)
0
1
2
3
4
5




1
1
2
of digits in answer
3
4
21
Dynamic programming
Storing intermediate results in a table for fast
look-up
input N 6
possible remainders upon dividing by N (6)
0
1
2
3
4
5




1
1
1
2
10
11
of digits in answer
3
4
22
Dynamic programming
Storing intermediate results in a table for fast
look-up
input N 6
possible remainders upon dividing by N (6)
0
1
2
3
4
5




1
1
1
2
10
11
of digits in answer
1
3
10
11
111
110
4
23
Dynamic programming
Storing intermediate results in a table for fast
look-up
input N 6
possible remainders upon dividing by N (6)
0
1
2
3
4
5




1
1
1
2
10
11
of digits in answer
1
3
10
11
111
110
1
1110
111
110
10
11
4
24
Problem Set 1 multiple.java
2 6 3 19 0
Input
Java Classes
0 marks the end of the input
BigInteger
LinkedListltStringgt
integers (N) with 2 lt N lt 10000
int
change!
Output
10 1110 111 11001
change!
the smallest (decimal) multiple of N with only
the digits 0 and 1 !
25
Coding tips multiple.java
import java.util.Scanner import
java.util.LinkedList import java.math.BigInteger
class multiple public static void pl(String
s) System.out.println(s) public static
void pld(String s) / pl(s) /
26
Coding tips multiple.java
import java.util.Scanner import
java.util.LinkedList import java.math.BigInteger
class multiple public static void pl(String
s) System.out.println(s) public static
void pld(String s) / pl(s) /
public static void main(String argv)
Scanner s new Scanner(System.in) // for
input int remainders //
the DP table LinkedListltStringgt LL
// a queue
27
Coding tips multiple.java
while (true) // while
there is input LL new LinkedListltStringgt()
// new, empty queue LL.addLast("1")
// starting value while
(LL.size() gt 0) // more data left?
String next LL.removeFirst() //
dequeue from front
the LinkedList class is a ready-made Deque
28
Coding tips multiple.java
the BigInteger constructor takes a String
BigInteger r0_big (new BigInteger(next0)).remain
der(input) int r0 r0_big.intValue()
// convert to an int if (r0 0)
// we're done! pl(next0)
// print the answer break
// go to next input
29
Coding tips multiple.java
the BigInteger constructor takes a String
BigInteger r0_big (new BigInteger(next0)).remain
der(input) int r0 r0_big.intValue()
// convert to an int if (r0 0)
// we're done! pl(next0)
// print the answer break
// go to next input
our table
if (remaindersr0 0) // have we seen
this one? remaindersr0 42 // 42
marks it as seen pld(" " next0 "," r0)
// for debugging LL.addLast( next0 )
// put next0 on the queue
30
Jotto!
A word-guessing game similar to mastermind
Sophomores
Juniors
Seniors
Me
fjord 3
fjord 0
fjord 1
fjord 2
31
Problem Set 1 bookcase.java
Input
  • 1
  • 4
  • 220 29
  • 195 20
  • 9
  • 180 30

number of data sets
number of books in this data set
height and width of each book
32
Problem Set 1 bookcase.java
Input
  • 1
  • 4
  • 220 29
  • 195 20
  • 9
  • 180 30

number of data sets
number of books in this data set
height and width of each book
Fit the books tightly onto a rectangular, 3-shelf
bookcase
220
29
20 9
200
30
180
30
33
Problem Set 1 bookcase.java
Input
  • 1
  • 4
  • 220 29
  • 195 20
  • 9
  • 180 30

number of data sets
number of books in this data set
height and width of each book
Fit the books tightly onto a rectangular, 3-shelf
bookcase
220
29
20 9
200
30
Output
180
30
What is the smallest total area for such a
bookshelf?
34
Problem Set 1 bookcase.java
Input
Thoughts?
  • 1
  • 4
  • 220 29
  • 195 20
  • 9
  • 180 30

number of data sets
number of books in this data set
height and width of each book
Fit the books tightly onto a rectangular, 3-shelf
bookcase
220
29
20 9
200
30
Output
180
30
What is the smallest total area for such a
bookshelf?
35
Tracking width, height, and books
Consider the books in order of height (decreasing)
  • Key decisions will be
  • given some number of books on the first two
    shelves,
  • the width of the shelves and the height of the
    shelves

width of Shelf 1
0




0
how many of the tallest books in top two shelves
1
Contains smallest possible height of shelf 2
2
3
36
See you next time!
37
Coaches Room
Write a Comment
User Comments (0)
About PowerShow.com