Skip to content

Instantly share code, notes, and snippets.

@jamessa
Created March 12, 2013 17:46
Show Gist options
  • Select an option

  • Save jamessa/5145169 to your computer and use it in GitHub Desktop.

Select an option

Save jamessa/5145169 to your computer and use it in GitHub Desktop.
// // main.c // 975485 // // Created by jamie on 3/12/13. // Copyright (c) 2013 jamie. All rights reserved. //
#include <stdio.h>
#include <stdlib.h>
#define max(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
int main(int argc, const char * argv[])
{
FILE *fp = fopen("A-large-practice.in", "r");
int number_of_cases;
fscanf(fp, "%d", &number_of_cases);
for (int i=0; i<number_of_cases; i++) {
long time = 0;
long bot[2] = {1,1};
long cost[2] = {0,0};
int number_of_steps;
fscanf(fp, "%d", &number_of_steps);
int side = 0;
for (int j=0; j<number_of_steps; j++) {
char cside;
long move_to;
fscanf(fp, " %c %ld", &cside, &move_to);
side = (cside=='O')?0:1;
time = max(time, labs(move_to - bot[side]) + cost[side] ) +1;
bot[side] = move_to;
cost[side] = time;
}
printf("Case #%d: %ld\n", i+1, time);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment