zoukankan      html  css  js  c++  java
  • uva 10050

     

      Problem D: Hartals 

    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. Assume h1 = 3, h2 = 4 and h3 = 8 where hi is the hartal parameter for party i ( i = 1, 2, 3). Now, we will simulate the behavior of these three parties for N = 14 days. One must always start the simulation on a Sunday and assume that there will be no hartals on weekly holidays (on Fridays and 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    


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

    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 le N le 3650$) giving the number of days over which the simulation must be run. The next line contains another integer P ( $1 le P le 100$) representing the number of political parties in this case. The i­th 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 le i le
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

    #include <iostream>
    #include <stack>
    #include <cstring>
    #include <cstdio>
    #include <string>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <fstream>
    #include <stack>
    #include <list>
    #include <sstream>
    
    using namespace std;
    
    #define ms(arr, val) memset(arr, val, sizeof(arr))
    #define N 4000
    #define INF 0x3fffffff
    #define vint vector<int>
    #define setint set<int>
    #define mint map<int, int>
    #define lint list<int>
    #define sch stack<char>
    #define qch queue<char>
    #define sint stack<int>
    #define qint queue<int>
    
    int days[N];
    int hoy[N];
    int main()
    {
        int t, p, h, n, ans;
        ms(hoy, 0);
        for (t = 6; t <= 3650; t += 7)
        {
            hoy[t] = hoy[t + 1] = 1;
        }
        scanf("%d", &t);
        while (t--)
        {
            scanf("%d", &n);
            scanf("%d", &p);
            ms(days, 0);
            while (p--)
            {
                scanf("%d", &h);
                for (int i = h; i <= n; i += h)
                {
                    days[i] = 1;
                }
            }
            ans = 0;
            for (int i = 1; i <= N; i++)
            {
                if (days[i] && !hoy[i])
                    ans++;
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    C# List<T>中Select List Distinct()去重复
    Spring.Net 简单入门学习
    [ASP.NET MVC]:
    打车题
    Vue------发布订阅模式实现
    Vue----数据响应原理
    小程序自定义导航栏_navigationStyle
    CleanWebpackPlugin最新版本使用问题
    js-事件函数调用简化
    用XHR简单封装一个axios
  • 原文地址:https://www.cnblogs.com/jecyhw/p/3903005.html
Copyright © 2011-2022 走看看