1 / 9

A chance to “improve” your C/C++ …

Two ACM programming skills. A chance to “improve” your C/C++ …. Preparation for the ACM competition. Problem Insight and Execution. 2. 1. Anxiety!. Get into the minds of the judges. Get into the minds of the judges. Key Skill #1: mindreading. 100%. 0%.

arin
Download Presentation

A chance to “improve” your C/C++ …

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. Two ACM programming skills A chance to “improve” your C/C++ … Preparation for the ACM competition ... Problem Insight and Execution ... 2 1 Anxiety! Get into the minds of the judges

  2. Get into the minds of the judges Key Skill #1: mindreading 100% 0% “What cases should I handle?” spectrum

  3. Key Skill #2: anxiety Anxiety!

  4. Dynamic Programming Strategy: create a table of partial results & build on it. divis.cc T(n) = number of steps yet to go T(n) = T(3n+1) + 1 if n odd T(n) = T(n/2) + 1 if n even

  5. Dynamic Programming Keys: create a table of partial results, articulate what each table cell means, then build it up... divis.cc j = items considered so far Table T 0 1 2 3 4 5 6 1 1 6 2 -3 0 the list 1 4 i = possible remainder the divisor 2 3 T[i][j] is 1 if i is a possible remainder using the first j items in the list.

  6. Dynamic programs can be short #include <cstdio> #include <iostream> #include <vector> vector<int> v(10000); vector<bool> m(100); // old mods vector<bool> m2(100); // new mods int n, k; bool divisible() { fill(m.begin(),m.end(),false); m[0] = true; for (int i=0; i<n; i++) { /* not giving away all of the code */ /* here the table is built (6 lines) */ } return m[0]; } int main() { cin >> n; // garbage while (cin >> n) { cin >> k; for (int i=0; i<n; i++) { cin >> v[i]; v[i] = abs(v[i]); v[i] %= k; } cout << (divisible() ? "D" : "Not d") << "ivisible\n"; } cout << endl; } acknowledgment: Matt Brubeck STL: http://www.sgi.com/Technology/STL

  7. General ACM Programming Try brute force first (or at least consider it) -- sometimes it will work fine… -- sometimes it will take a _bit_ too long -- sometimes it will take _way_ too long Best bugs from last week: getting the input in the “pea” problem: filling in the table in the “divis” problem: for (int j=1 ; j<N ; ++j) { cin >> Array[i]; } Table[i + n % k] = 1; Table[i - n % k] = 1;

  8. New Problem Word Chains hertz jazz hajj zeroth doze aplomb ceded dozen envy ballistic yearn Input A list of words Output yes or no -- can these words be chained together such that the last letter of one is the first letter of the next… ?

  9. Knapsack Problem objectwt.val. 1 3 8 2 2 5 3 1 1 4 2 5 Maximize loot w/ weight limit of 4. w Weight available for use Number of objects considered 0 1 2 3 4 1 V(n,w) = max value stealable w/ ‘n’ objects & ‘w’ weight 2 3 4 n V(n,w) =

More Related