A solution for the "Hartals" problem
Problem description:
http://icpcres.ecs.baylor.edu/onlinejudge/external/100/10050.html
Author: Joana Matos Fonseca da Trindade
Date: 2008.04.06
1 2 /* 3 * Solution for the "Hartals" problem. 4 * UVa ID: 10050 5 */ 6 #include <iostream> 7 8 #define NDAYS 3651 9 10 using namespace std; 11 12 /* simulation time (in days) */ 13 int st[NDAYS]; 14 15 /* main */ 16 int main (int argc, const char *argv[]) { 17 int nc; /* number of cases */ 18 int nd; /* number of days */ 19 int np; /* number of political parties */ 20 int h; /* current hartal number */ 21 int dl; /* days lost */ 22 23 cin >> nc; 24 25 /* for each case.. */ 26 for (int i=0; i<nc; i++) { 27 cin >> nd; 28 cin >> np; 29 30 /* initialize simulation table */ 31 for (int j=0; j<=nd; j++) { 32 st[j] = 0; 33 } 34 dl = 0; /* init days lost counter */ 35 36 /* update with hartal for each party */ 37 for (int j=0; j<np; j++) { 38 cin >> h; 39 for (int k=1; k*h-1<=nd; k++) { 40 st[k*h-1] = 1; /* set lost day flag */ 41 } 42 } 43 44 /* calculate number of days lost */ 45 for (int j=0; j<nd; j++) { 46 /* if it's not a friday or a saturday */ 47 if ((j%7 != 5) && (j%7 != 6) && (st[j] == 1)) { 48 dl++; 49 } 50 } 51 cout << dl << endl; 52 } 53 54 } 55 56