#define TEAM 0 /* Your team # here */ #define PROBLEM NUMBER /* The problem # here */ #include #include #include #include FILE *in=0; FILE *out=0; void solve_problem(); int debug = 0; /*-------------------------------------------------------*/ int main(int argc, char *argv[]) { char inputFilename[64]; char outputFilename[64]; int teamNumber = TEAM; int j; sprintf(inputFilename, "prob%d.dat", PROBLEM); sprintf(outputFilename,"prob%d.out", PROBLEM); /* Process the command line arguments. This can change the filenames and/or team number */ j=1; while (jx - common->x)*(toy->y - common->y) - (partition->y - common->y)*(toy->x - common->x)) > 0.0) return TRUE; else return FALSE; } /*-------------------------------------------------------*/ void addToyToCounts(point *toy) { int first, mid, last; /* binary search */ first = 1; last = numberPartitions+1; while (first <= last) { mid = (first + last) / 2; if (leftOfPartition(&partitions[mid][LOWER], &partitions[mid][UPPER], toy) ) { /* Is it to the right of the previous partition? */ if ( ! leftOfPartition(&partitions[mid-1][LOWER], &partitions[mid-1][UPPER], toy) ) { counts[mid-1]++; return; } else last = mid-1; } else first = mid+1; } printf("Error - search failed\n"); } /*-------------------------------------------------------*/ void solve_problem() { int j; int firstProblem = 1; point toy; while ( TRUE ) { fscanf(in, "%d", &numberPartitions); if (numberPartitions == 0) break; fscanf(in, "%d %f %f %f %f\n", &numberToys, &upperLeft.x, &upperLeft.y, &lowerRight.x, &lowerRight.y); for (j=0; j<=numberPartitions; j++) counts[j] = 0; /* Add the left wall as a partition */ partitions[0][UPPER].x = upperLeft.x; partitions[0][UPPER].y = upperLeft.y; partitions[0][LOWER].x = upperLeft.x; partitions[0][LOWER].y = lowerRight.y; for (j=1; j<=numberPartitions; j++) { partitions[j][UPPER].y = upperLeft.y; partitions[j][LOWER].y = lowerRight.y; fscanf(in, "%f %f\n", &partitions[j][UPPER], &partitions[j][LOWER]); } /* Add the right wall as a partition */ partitions[j][UPPER].x = lowerRight.x; partitions[j][UPPER].y = upperLeft.y; partitions[j][LOWER].x = lowerRight.x; partitions[j][LOWER].y = lowerRight.y; if (debug) { for (j=0; j