您的位置:首页 > 其它

UVA - 10050 Hartals

2016-07-26 19:59 489 查看
题目大意:给 T 个样例,连续 N 天,从周日开始,P 个队伍,每个队伍罢工的日子是所给队伍数字的倍数,多个队伍在同一天罢工只算一次,且周五周六不算,问罢工天数。

解题思路:模拟,把罢工天数置为 1,每周五周六置为 0,最后扫一遍。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctype.h>
using namespace std;
int team[120];
int day[10000];
int main() {
int T;
scanf("%d", &T);
while (T--) {
memset(day, 0, sizeof(day));
int N, P;
scanf("%d%d", &N, &P);
for (int i = 0; i < P; i++)
scanf("%d", &team[i]);
for (int i = 0; i < P; i++) {
int tag = 1;
while (team[i]*tag <= N) {
day[team[i]*tag] = 1;
tag++;
}
}
for (int i = 6; i <= N; i += 7) {
day[i] = 0;
day[i+1] = 0;
}

int cnt = 0;
for (int i = 1; i <= N; i++)
if (day[i] == 1)
cnt++;
printf("%d\n", cnt);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva