start) right=mid; else left=mid; } // at end of binary search, "left" points to index of last end"> start) right=mid; else left=mid; } // at end of binary search, "left" points to index of last end">
Download presentation
Presentation is loading. Please wait.
Published byEvangeline Maxwell Modified over 9 years ago
1
USACO’s this weekend! Aren’t you EXCITED ?!? :D
2
PotW Solution (20 pts) Scanner scan = new Scanner(System.in); scan.useDelimiter("[^0-9]+"); int n=scan.nextInt(); int preve=-1,c=0; for(int i=1;i<=n;i++) { int start = scan.nextInt()*60 + scan.nextInt(); int end = scan.nextInt()*60 + scan.nextInt(); if(start>=preve) { preve=end; c++; } System.out.println(c);
3
+15 Bonus Solution Scanner scan = new Scanner(System.in); scan.useDelimiter("[^0-9]+"); int n=scan.nextInt(); int[] endt=new int[n+1],maxn=new int[n+1],maxt=new int[n+1]; endt[0]=-1; // add dummy segment maxn[0]=0; maxt[0]=0; for(int i=1;i<=n;i++) { int start = scan.nextInt()*60 + scan.nextInt(); int end = scan.nextInt()*60 + scan.nextInt(); endt[i]=end; // save end int left=0,right=i,mid; while(left+1 < right) { // binary search for last end landing before start mid = (left+right)/2; if(endt[mid]>start) right=mid; else left=mid; } // at end of binary search, "left" points to index of last end
4
Bonus Solution (cont.) int curn=maxn[left]+1; int curt=maxt[left]+end-start; // memoize current values maxn[i]=maxn[i-1]; maxt[i]=maxt[i-1]; if(curn>maxn[i]) { maxn[i]=curn; // superior in terms of number maxt[i]=curt; } else if(curn==maxn[i] && curt>maxt[i]) maxt[i]=curt; // tie, break tie by time } System.out.println(maxn[n]); System.out.println(maxt[n]);
5
USACO Schedule! Nov 11-14: November Contest Dec 9-12: December Contest Jan 6-9: January Contest Feb 3-6: February Contest Mar 2-5: March Contest April: US Open June: Training Camp September: IOI 2012 in Milan, Italy Also on lynbrookcs.com/usaco-schedule/
6
USACO Tips/Reminders! You should TAKE IT o usaco.org You should PREPARE FOR IT o train.usaco.org You should READ THE PROBLEM CAREFULLY You should TEST YOUR PROGRAMS o Read the test data o Check the test data by hand o Check your algorithm by hand o Make your own test data o Test your program Don’t waste your time on the wrong things! o You are allowed to copy code off the internet for algorithms you can’t remember Cite your sources General info about USACO on Oct. 3 meeting slides
7
New PotW! Nope! Take the USACO instead! o Worth 5 points (if you actually submit something) o For credit, mark that you participated on the attendance sheet next meeting (or email us if you for some reason can’t make it to the next meeting)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.