70 likes | 330 Views
USACO’s this weekend!. Aren’t you EXCITED ?!? :D. 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 ();
E N D
USACO’s this weekend! Aren’t you EXCITED?!? :D
PotW Solution (20 pts) Scanner scan = newScanner(System.in); scan.useDelimiter("[^0-9]+"); intn=scan.nextInt(); intpreve=-1,c=0; for(inti=1;i<=n;i++) { intstart = scan.nextInt()*60 + scan.nextInt(); intend = scan.nextInt()*60 + scan.nextInt(); if(start>=preve) { preve=end; c++; } } System.out.println(c);
+15 Bonus Solution Scanner scan = newScanner(System.in); scan.useDelimiter("[^0-9]+"); intn=scan.nextInt(); int[] endt=newint[n+1],maxn=newint[n+1],maxt=newint[n+1]; endt[0]=-1; // add dummy segment maxn[0]=0; maxt[0]=0; for(inti=1;i<=n;i++) { intstart = scan.nextInt()*60 + scan.nextInt(); intend = scan.nextInt()*60 + scan.nextInt(); endt[i]=end; // save end intleft=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
Bonus Solution (cont.) intcurn=maxn[left]+1; intcurt=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; } elseif(curn==maxn[i] && curt>maxt[i]) maxt[i]=curt; // tie, break tie by time } System.out.println(maxn[n]); System.out.println(maxt[n]);
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/
USACO Tips/Reminders! • You should TAKE IT • usaco.org • You should PREPARE FOR IT • train.usaco.org • You should READ THE PROBLEM CAREFULLY • You should TEST YOUR PROGRAMS • Read the test data • Check the test data by hand • Check your algorithm by hand • Make your own test data • Test your program • Don’t waste your time on the wrong things! • 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
New PotW! • Nope! • Take the USACO instead! • Worth 5 points (if you actually submit something) • 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)