PC 110203 Hartals //水题 Hash 模拟



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 = 3h2 = 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.


 1234567891011121314
DaysSuMoTuWeThFrSaSuMoTuWeThFrSa
Party 1  x  x  x  x  
Party 2   x   x   x  
Party 3       x      
Hartals  12   34  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.

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. Theith 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

WA了一次,意外。。。竟然蠢到 让 t % 7 == 7 。。你说这能有这数么。。


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
//	freopen("c:\\in.txt","r",stdin);
	int day[3651];
	int cases, days, i, j, parties, p, t, countn;
	cin>>cases;
	while (cases--)
	{
		cin>>days;
		cin>>parties;
		memset(day, 0, sizeof(day));
		countn = 0;
		for (i=1; i<=parties; i++)
		{
			cin>>p;
			t=p;
			while (t<=days)
			{
				if (t%7 != 6 && t%7 != 0)
				{ 
				 	day[t] = 1;
				 	t += p;
				}
				else t+=p ;
			}
		}
		for (i=1; i<=days; i++)
		{
			if (day[i]==1) ++countn;
		}
		cout<<countn<<endl;
	}
		
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值