uva10050

来源:互联网 发布:淘宝买家申请售后换货 编辑:程序博客网 时间:2024/05/22 14:17

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=991

10050 - Hartals

Time limit: 3.000 seconds

Problem D:HartalsA social research organization has determined a simple set ofparameters to simulate the behavior of the political parties of ourcountry. One of the parameters is a positive integerh(called the hartal parameter) that denotes the averagenumber of days between two successive hartals (strikes)called by the corresponding party. Though the parameter is far toosimple to be flawless, it can still be used to forecast the damagescaused by hartals. The following example will give you aclear idea:


Consider three political parties. Assume h1 =3,h2 = 4 and h3 = 8 wherehi is the hartal parameter forparty i(i = 1, 2, 3).Now, we will simulate the behavior of these three parties forN = 14 days. One must always start the simulation on aSunday and assume that there will be no hartals on weeklyholidays (on Fridays and Saturdays).


1234567891011121314DaysSuMoTuWeThFrSaSuMoTuWeThFrSaParty 1xxxxParty 2xxxParty 3xHartals12345


The simulation above shows that there will be exactly 5hartals (on days 3, 4, 8, 9 and 12) in 14 days. There willbe no hartal on day 6 since it is a Friday. Hence we lose5 working days in 2 weeks.

In this problem, given the hartal parameters for severalpolitical parties and the value of N, your job is todetermine the number of working days we lose in those Ndays.

Input

The first line of the input consists of a single integerT giving the number of test cases to follow.

The first line of each test case contains an integerN ($7 \le N \le 3650$) giving the number of days over which the simulationmust be run. The next line contains another integer P ($1 \le P \le 100$) representing the number of political parties inthis case. The i­th of the next Plines contains a positive integer hi(which will never be a multiple of 7) giving the hartalparameter for party i ($1 \le i \le
P$).

Output

For each test case in the input output the number of workingdays we lose. Each output must be on a separate line.

Sample Input

2143348100412152540

Sample Output

515

 

题意:在按星期算的时间里每到某一天都要罢工,求在指定的天数内罢工的天数

 

#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int a[4000];
int  day[4000];//保存输入的数据
int main()
{
  //freopen("text.txt","r",stdin);
    int t;
   scanf("%d",&t);//有多少组测试数据
   while(t--)
    {
       int n,i,j,m;
       scanf("%d",&m);//限定的天数
       scanf("%d",&n);//有几个政党(就是有几种不同类型的罢工)
       for(i=1;i<=n;i++)
       {
           scanf("%d",&a[i]);//罢工的类型
       }
       memset(day,0,sizeof(day));//初始化为0
       for(i=1;i<=m;i++)
       {
           for(j=1;j<=n;j++)
           {
               if(i%a[j]==0&&i%7!=6&&i%7!=0)//判断条件(最关键的)
               {
                   day[i]=1;
               }
           }
       }
       int count=0;
       for(i=1;i<=m;i++)
       {
           if(day[i]==1)
           count++;
       }
       printf("%d\n",count);
    }
    return0;
}

原创粉丝点击