意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

UVA 10050 - Hartals

来源:恒创科技 编辑:恒创科技编辑部
2022-08-25 14:50:38


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.


UVA 10050 - Hartals

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.

UVA 10050 - Hartals_UVA


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;
}


上一篇: 租用美国服务器:潜在的风险与应对策略。 下一篇: Dv-Hop Algorithm