USACO 3.2 Spinning Wheels

This problem can be treated as a search problem. The search space is the set of states of all wedges of all wheels. The match criteria is at any give second, each wheel out of five wheels should have at least one wedge whose angle and ‘covers’ (the extent) that overlaps with (again, at least one) wedges from other wheels.
The catch is we only need to examine the first 360 second and bail out as soon as we have a match, because the state of the wheel and wedges will be reset to the same original state after 360 sec (a cycle).

#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <utility>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <climits>
#include <sstream>

using namespace std;

typedef struct wheel {
int speed;
int wedgeCnt;
int start[5];
int angle[5];
} tWheel;

tWheel wheels[5];

int main(){
ifstream fin("spin.in");
ofstream fout("spin.out");

for (int i = 0; i < 5; ++i) {
fin >> wheels[i].speed >> wheels[i].wedgeCnt;
for (int j = 0; j < wheels[i].wedgeCnt; ++j) {
fin >> wheels[i].start[j] >> wheels[i].angle[j];
}
}

for (int m = 0; m <= 360; ++m) {
vector<int> align(360, 0);
for (int i = 0; i < 5; ++i) {
tWheel wheel = wheels[i];
for (int j = 0; j < wheel.wedgeCnt; ++j) {
int start = (wheel.start[j] + wheel.speed * m) % 360;
for (int k = start; k <= start + wheel.angle[j]; ++k) {
align[k % 360]++;
}
}
}
for (int i = 0; i < 360; ++i) {
if (align[i] == 5) {
cout << m << endl;
fout << m << endl;
return 0;
}
}
}
cout << "none" << endl;
fout << "none" << endl;
}