UVa 10050 - Hartals
Description:
A social research organization has determined a simple set of parameters to simulate the behavior of
the political parties of our country. One of the parameters is a positive integer h (called the hartal
parameter) that denotes the average number of days between two successive hartals (strikes) called by
the corresponding party. Though the parameter is far too simple to be flawless, it can still be used to
forecast the damages caused by hartals. The following example will give you a clear idea:
Consider three political parties.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.
Input
The first line of the input consists of a single integer T giving the number of test cases to follow.
The first line of each test case contains an integer N (7 ≤ N ≤ 3650) giving the number of days over
which the simulation must be run. The next line contains another integer P (1 ≤ P ≤ 100) 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 (1 ≤ i ≤ P).
Output
For each test case in the input output the number of working days we lose. Each output must be on a separate line.
Sample Input
2
14
3
3
4
8
100
4
12
15
25
40
Sample Output
5 15
Solution
#include<stdio.h>int main() { int arr[100][3650],h[100],party,day,n,p,count,t,i,j; scanf("%d",&t); for(i=1; i<=t; i++) { scanf("%d",&n); scanf("%d",&p); for(j=1; j<=p; j++) scanf("%d",&h[j]); count=0; for(day=0; day<=n; day++) { for(party=1; party<=p; party++) { if(day%h[party]==0) { if(day%7==0 || (day+1)%7==0) continue; else { count++; break; } } } } printf("%d\n",count); } return 0;
}
Comments
Post a Comment