UVa 10050 - Hartals

本文解析UVa10050-Hartals模拟题,介绍如何通过模拟政治罢工来预测损失的工作日数量。考虑每周休息日的影响,给出了一种实现思路及代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UVa 10050 - Hartals

1题目

===================


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. Assumeh1= 3,h2= 4 andh3= 8 wherehiis thehartal parameterfor partyi(i= 1, 2, 3). Now, we will simulate the behavior of these three parties forN= 14 days. One must always start the simulation on a Sunday and assume that there will be nohartalson weekly holidays (on Fridays and Saturdays).


1234567891011121314
Days
SuMoTuWeThFrSaSuMoTuWeThFrSa
Party 1xxxx
Party 2xxx
Party 3x
Hartals12345


The simulation above shows that there will be exactly 5hartals(on days 3, 4, 8, 9 and 12) in 14 days. There will be nohartalon 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 ofN, your job is to determine the number of working days we lose in thoseNdays.

Input

The first line of the input consists of a single integerTgiving 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 simulation must be run. The next line contains another integerP($1 \le P \le 100$) representing the number of political parties in this case. Thei­th of the nextPlines contains a positive integerhi(which will never be a multiple of 7) giving thehartal parameterfor partyi($1 \le i \leP$).

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



Miguel Revilla
2000-12-26

===================

2思路

这是一个模拟题,相当于给了n天,把天的序号为a1倍数,a2倍数,…,an倍数的那些 天选出来,排除周五周六,看看选中的一共多少天。奇怪的是这个题为什么会划分在 Data Structure的List分类里,而且我的用时怎么也到不了最好的0.000s,在网上搜 了其它人的答案,基本和我用时差不多。我怀疑有简便的算法,通过计算而非模拟来 解决问题,但是一直找不到答案。先记下模拟的代码吧。

3代码

/*
 * Problem: UVa 10050 Hartals
 * Lang: ANSI C
 * Time: 0.012s
 * Author: minix
 */
#include <stdio.h>
#include <string.h>

#define N 3650
#define P 100
int s[N];

int main() {
  int n, m, d, i, j, k, t, r, h;
  scanf ("%d", &n);
  for (i=0; i<n; i++) {
    memset (s, 0, sizeof(s[0])*N);
    scanf ("%d", &d);
    scanf ("%d", &m);
    for (j=0; j<m; j++) {
      scanf ("%d", &h);
      t = h;
      while (t <= d) {
        s[t] = 1;
        t += h;
      }
    }
    t = 7; r = 0;
    for (j=1; j<=d; j++) {
      if (t!=5&&t!=6&&s[j]) r ++;
      t ++; if (t>7) t-= 7;
    }
    printf ("%d\n", r);
  }
  return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值