UVA 10050 - Hartals

Description:
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.
这里写图片描述
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.

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 ≤ 3, 650), 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. 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, output the number of working days lost 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 <cstring>

using namespace std;

int lost[3650+5];//the number of lost days

int calLostDay(int parties, int hartals[], int days){
    int lostDay=0;
    for(int i=0; i<parties; i++){
        int k=hartals[i];
        while(k<=days){
            if(!lost[k] && k%7!=6 && k%7!=0){
                lostDay++;
                lost[k] = 1;
            }
            k+=hartals[i];
        }
    }

    return lostDay;
}

int main(){
    int days;//the number of days which the simulation must be run
    int cases;//the number of test cases
    int parties;//the number of political parties
    int hartals[100+5];//the hartal parameters for parties

    cin >> cases;
    while(cases--){
        memset(lost, 0, sizeof(lost));
        cin >> days >> parties;
        for(int i=0; i<parties; i++)
            cin >> hartals[i];
        cout << calLostDay(parties, hartals, days) << endl;
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全评估测试题大模型安全评估测试题关键词库生成内容测试题库应拒答测试题库非拒答测试题大模型安全
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值