Consider three political parties. Assume h1 = 3, h2 = 4 and h3 = 8 where hi is the hartal parameter for party i ( i = 1, 2, 3). Now, we will simulate the behavior of these three parties for N = 14 days. One must always start the simulation on a Sunday and assume that there will be no hartals on weekly holidays (on Fridays and Saturdays).
The simulation above shows that there will be exactly 5 hartals (on days 3, 4, 8, 9 and 12) in 14 days. There will be no hartal on day 6 since it is a Friday. Hence we lose 5 working days in 2 weeks.
In this problem, given the hartal parameters for several political parties and the value of N, your job is to determine the number of working days we lose in those N days.
The first line of each test case contains an integer N ( ) giving the number of days over which the simulation must be run. The next line contains another integer P ( ) representing the number of political parties in this case. The ith of the next P lines contains a positive integer hi (which will never be a multiple of 7) giving the hartal parameter for party i ( ).
2 14 3 3 4 8 100 4 12 15 25 40
Solution:Simulation, use array mapping.
Source Code://Mon Mar 14 14:17:16 CDT 2011
using namespace std;
int main(int argc, char* argv)
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
cin >> T;
int N, P;
cin >> N >> P;
vector<bool> flag(N, false);
for (int k = 0; k < P; k++)
cin >> days;
for (int i = days-1; i < N; i += days)
flag[i] = true;
int count = 0;
for (int i = 0; i < N; i++)
if (i % 7 != 5 && i % 7 != 6 && flag[i])
cout << count << endl;