Uva 10050 2015.6.7

来源:互联网 发布:js后退不刷新页面 编辑:程序博客网 时间:2024/05/29 16:16

/*

   Source: Uva 10050 Hartals

   Category: 模拟

   Abstract: 给定一个天数N,以及各个机构罢工的间隔Pi,求计算在这N天里面,有多少天是罢工天。

              周五和周六不罢工。

   Idea:

       用一个bool数组Day来标记当天是否有人罢工,true表示没人罢工,false表示有人罢工

       Day[i],若i是Pi的倍数,则标记为false

       最后单独处理周五和周六,都为true

   Notice:

       周五是对于7余6,周六是对于7余0.

       刚开始直接用6乘以j,7乘以j,是不对的。所以WA了。

*/

 

10050  Hartals

Asocial research organization has determined a simple set of parameters tosimulate the behavior of the political parties of our country. One of the parametersis a positive integerh (called the hartal parameter) that denotesthe average numberof days betweentwo successivehartals (strikes) called by thecorresponding party. Though theparameter is far too simple to be flawless,it can still be used to forecast the damages causedbyhartals. The following example will give you a clear idea:

Consider three politicalparties. Assume h1 = 3, h2 = 4 and h3 = 8 where hi is the hartal parameter for partyi(i= 1, 2, 3). Now, we will simulatethe behavior of these threeparties forN = 14 days. One mustalways start the simulation on a Sundayand assume that there will be nohartals on weekly holidays (on Fridays and Saturdays).

 

 

 

Days

1

 

Su

2

 

Mo

3

 

Tu

4

 

We

5

 

Th

6

 

Fr

7

 

Sa

8

 

Su

9

 

Mo

10

 

Tu

11

 

We

12

 

Th

13

 

Fr

14

 

Sa

Party

1

 

 

x

 

 

x

 

 

x

 

 

x

 

 

Party

2

 

x

 

x

 

x

Party

3

 

 

 

x

 

 

Hartals

 

 

1

2

 

 

 

3

4

 

 

5

 

 

 

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 nohartal on day 6 since it is a Friday.  Hencewe lose 5 working days in 2 weeks.

In this problem, given the hartal parameters for several politicalparties and the value ofN , your job is to determine the number of workingdays we lose in those N days.

 

Input

The first line of the input consists of a singleinteger T giving the number of testcases to follow.

The first line of each test casecontains an integer N (7≤ N ≤ 3650) giving the number of days over which the simulation must be run. The next line contains anotherintegerP (1 ≤ P ≤ 100) representing the number of political partiesin this case. Theith of the next P lines contains a positive integerhi (which will never be a multiple of 7) giving the hartal parameter for partyi (1 ≤ i ≤ P ).

 

Output

For each testcase in the input output the number of working days we lose. Each output must be on a separate line.

 

SampleInput

2

14

3

3

4

8

100

4

12

15

25

40

 

Sample Output

5

15

 


#include<stdio.h>#include<stdlib.h>#include<string.h>#define MAXN 4000bool Day[MAXN];int T,N,Pi,numPi;int friday = -1, saturday =0;int main(){    scanf("%d",&T);    for (int k=1;k<=T;k++)    {        memset(Day,true, sizeof(Day));        scanf("%d",&N);        scanf("%d",&numPi);        for(int i=1;i<=numPi;i++)        {            scanf("%d",&Pi);            int nPi=N/Pi+1;            for(int j=1;j<=nPi;j++)                Day[j*Pi]=false;        }        int Fri=N/7+1;        for(int j=1;j<=Fri;j++)            Day[j*7+friday]=true;        int Sat=N/7+1;        for(int j=1;j<=Sat;j++)            Day[j*7+saturday]=true;        int num=0;        for(int i=1;i<=N;i++)            if (!Day[i]) num++;        printf("%d\n",num);    }    return 0;}


0 0
原创粉丝点击