USACO 3.2.3 – Spinning Wheels


#include <cstdio>
#include <cstring>

int main() {
	freopen("spin.in", "r", stdin), freopen("spin.out", "w", stdout);
	int v[5], nwidges[5], wd[5][5][2], open[360] = { 0 };
	for (int i = 0; i < 5; i++) {
		scanf("%d %d", v + i, nwidges + i);
		for (int j = 0; j < nwidges[i]; j++)
			scanf("%d %d", wd[i][j], wd[i][j] + 1);
	}
	for (int t = 0; t < 360; memset(open, 0, sizeof open), t++)
		for (int w = 0; w < 5; w++)
			for (int n = 0; n < nwidges[w]; n++)
				for (int p=t*v[w]+wd[w][n][0]; p<=t*v[w]+wd[w][n][0]+wd[w][n][1]; p++) {
					if (++open[p % 360] == 5) {
						printf("%d\n", t);
						return 0;
					}
				}

	puts("none");
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: