PC/UVa:110203/10050
根据每个政党的罢工周期,去掉周五和周六,最后再统计综合就好了。
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int T = 0;
cin >> T;
for (int i = 0; i < T; i++)
{
int N, P;
cin >> N >> P;
vector<int> vh(P, 0);
vector<int> vd(N + 1, false);
for (int k = 0; k < P; k++)
{
cin >> vh[k];
}
int today;
for (int k = 0; k < P; k++)
{
for (int day = vh[k] - 1; day < N; day += vh[k])
{
today = day % 7;
if (today == 5 || today == 6) continue;
else vd[day] = true;
}
}
int cnt = 0;
for (auto b : vd)
{
if (b) cnt++;
}
cout << cnt << endl;
}
return 0;
}
/*
2
14
3
3
4
8
100
4
12
15
25
40
*/
本文探讨了Hartals问题的解决策略,通过分析政党罢工周期,排除周五和周六,统计有效罢工天数。使用C++实现,涉及数组和循环结构,展示了算法设计与实现的过程。
229

被折叠的 条评论
为什么被折叠?



