USACO OPEN07 Problem 'flowers' Analysis
by Rob Kolstad
The key to solving this problem is the creation and tallying of an
array that represents the long row of flowers. Each starting location
and increment has its flowers tallied into the flower array. Finally,
a quick count yields the number of empty slots:
#include <stdio.h>
int flowers[10000];
main () {
FILE *fin=fopen("flowers.in","r");
FILE *fout=fopen("flowers.out","w");
int f, k, i, j, n, l;
fscanf (fin, "%d %d", &f, &k);
for (j = 0; j < k; j++) {
fscanf (fin, "%d %d", &l, &i);
for (n = l-1; n < f; n+= i)
flowers[n] = 1;
}
n = 0;
for (j = 0; j < f; j++)
if (flowers[j] == 0)
n++;
fprintf (fout, "%d\n", n);
exit (0);
}