Qualification 4 August 16-17, 2005 Match summary This set may have been the easiest overall. The easy, DayPlanner, required some simple string parsing and time manipulation. The hard, TheCoderMan, had a few tricky cases but no recursion. As expected, many people did well on this set. 14 coders were able to score over 900. Yi_Zhang led the room, with gladius and bladerunner close behind. The ProblemsDayPlannerUsed as: Division One - Level One:
Here we must determine which tasks occurred first and last. For each element of the input, we parse out the time and compute the number of minutes it represents. Then we check if this time represents the minimum or maximum found thus far. Java code follows: public String getEnds(String[] tasks) { int m = 10000000, M = 0, mb = 0, Mb = 0; for (int i = 0; i < tasks.length; i++) { String curr[] = tasks[i].split("[ :]"); int min = Integer.parseInt(curr[0])*60 + Integer.parseInt(curr[1]); if (min < m) { m = min; mb = i; } if (min > M) { M = min; Mb = i; } } return tasks[mb].split("[ :]")[2]+"-"+tasks[Mb].split("[ :]")[2]; }TheCoderMan Used as: Division One - Level Three:
Here we must look at each of our friends and determine if they are eligible to rate TheCoderMan. We can throw out any friend that didn't rate TheCoderMan. For the remaining friends, we compute their average deviation from our ratings. This is done by looping over their ratings, and see where they rated a movie we did. For all viable friends, we average their ratings of TheCoderMan and return this value. Java code follows: double dev(String a, String b) { int ret = 0, cnt = 0; for (int i = 0; i < a.length(); i++) { if (a.charAt(i) == 'X' || b.charAt(i) == 'X') continue; cnt++; ret += Math.abs(a.charAt(i) - b.charAt(i)); } return cnt == 0 ? 10 : ret*1.0/cnt; } public double evaluateMovie(String ys, String[] fs, int max) { double ret = 0; int cnt = 0; for (int i = 0; i < fs.length; i++) { double temp = dev(ys,fs[i]); char c = fs[i].charAt(fs[i].length() - 1); if (temp <= max && c != 'X') { ret += c-'0'; cnt++; } } return cnt == 0 ? -1 : ret/cnt; } |
|