Skip to main content

UVa 10050 - Hartals Solution

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

Populer Article

UVa 10082 - WERTYU Solution

UVa  10082 - WERTYU Description:   A common typing error is to place the  hands on the keyboard one row to the  right of the correct position. So ‘Q’ is  typed as ‘W’ and ‘J’ is typed as ‘K’ and  so on. You are to decode a message typed in this manner. Input Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except  Q, A, Z), or punctuation shown above [except back-quote (‘)]. Keys labelled with words [Tab, BackSp,  Control, etc.] are not represented in the input. Output You are to replace each letter or punction symbol by the one immediately to its left on the ‘QWERTY’  keyboard shown above. Spaces in the input should be echoed in the output. Sample Input O S, GOMR YPFSU/ Sample Output I AM FINE TODAY.  Solution #include<stdio.h> int main () { char str[10000], key[]={'`','1','2','3','4','5','6','7','8','9','0', '-','=','...

UVa 10062 - Tell me the frequency Solution

UVa  10062 - Tell me the frequency Description:  Given a line of text you will have to find out the frequencies of the ASCII characters present in it. The  given lines will contain none of the first 32 or last 128 ASCII characters. Of course lines may end with  \n and \r but always keep those out of consideration. Input Several lines of text are given as input. Each line of text is considered as a single input. Maximum  length of each line is 1000. Output Print the ASCII value of the ASCII characters which are present and their frequency according to the  given format below. A blank line should separate each set of output. Print the ASCII characters in the  ascending order of their frequencies. If two characters are present the same time print the information  of the ASCII character with higher ASCII value first. Input is terminated by end of file. Sample Input AAABBC 122333 Sample Output 67 1 66 2 65 3 49 1 50 2 51 3 Solution #include<stdio.h...

UVa 10079 - Pizza Cutting Solution

UVa 10079 - Pizza Cutting Description:  When someone calls Ivan lazy, he claims that it is his intelligence that helps him to be so. If his intelligence allows him to do something at less physical effort, why should he exert more? He also claims that he always uses his brain and tries to do some work at less effort; this is not his laziness, rather this is his intellectual smartness. Once Ivan was asked to cut a pizza into seven pieces to distribute it among his friends. (Size of the pieces may not be the same. In fact, his piece will be larger than the others.) He thought a bit, and came to the conclusion that he can cut it into seven pieces by only three straight cuts through the pizza with a pizza knife. Accordingly, he cut the pizza in the following way (guess which one is Ivan’s piece): One of his friends, who never believed in Ivan’s smartness, was startled at this intelligence. He thought, if Ivan can do it, why can’t my computer? So he tried to do a similar (but not ex...