JOIN
Get Time
statistics_w  Match Editorial
2005 TopCoder Open
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 Problems

DayPlanner discuss it
Used as: Division One - Level One:
Value 250
Submission Rate 339 / 353 (96.03%)
Success Rate 299 / 339 (88.20%)
High Score LunaticFringe for 247.69 points (2 mins 12 secs)
Average Score 206.75 (for 299 correct submissions)

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 discuss it
Used as: Division One - Level Three:
Value 750
Submission Rate 297 / 353 (84.14%)
Success Rate 222 / 297 (74.75%)
High Score Yi_Zhang for 698.52 points (6 mins 15 secs)
Average Score 494.02 (for 222 correct submissions)

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;
}

Author
By brett1479
TopCoder Member