若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1504: Hartals

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,001

题目描述

Political parties in Bangladesh show their muscle by calling for regular hartals (strikes), which cause considerable economic damage. For our purposes, each party may be characterized by a positive integer h called the hartal parameter that denotes the average number of days between two successive strikes called by the given party. Consider three political parties. Assume h1 = 3, h2 = 4, and h3 = 8, where hi is the hartal parameter for party i. We can simulate the behavior of these three parties for N = 14 days. We always start the simulation on a Sunday. There are no hartals on either Fridays or Saturdays.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

Days
Su
Mo
Tu
We
Th
Fr
Sa
Su
Mo
Tu
We
Th
Fr
Sa

Party 1

x

x

x

x

Party 2

x

x

x

Party 3

x

Hartals

1
2

3
4

5

There will be exactly five hartals (on days 3, 4, 8, 9, and 12) over the 14 days. There is no hartal on day 6 since it falls on Friday. Hence we lose five working days in two weeks. Given the hartal parameters for several political parties and the value of N, determine the number of working days lost in those N days.

输入

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<=3, 650), giving the number of days over which the simulation must be run. The next line contains another integer P ( 1P100) representing the number of political parties. 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 ( 1iP).

输出

For each test case, output the number of working days lost on a separate line.

样例输入

2
14
3
3
4
8
100
4
12
15
25
40


样例输出

5
15


参考代码

#include<stdio.h>
int a[3700];
int main() 
{
    int t,n,num,x,i,count;
    scanf("%d",&t);
    while(t--) 
    {
        scanf("%d",&num);
        for (i=0;i<=num;i++)
                    a[i]=0;
        scanf("%d",&n);
        while(n--) 
        {
            scanf("%d",&x);
            for (i=1;i*x<=num;i++)
                            a[i*x]=1;
        }
        count=0;
        for (i=1;i<=num;i++) 
        {
            if(i%7==6) 
            {
                i++;
                continue;
            } else 
            {
                if(a[i])count++;
            }
        }
        printf("%dn",count);
    }
    return 0;
}

解析

暂无

hustoj

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

原站点 Skip Dreams孤独患者
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist