10050-Hartals

出處http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=991

解題策略

使用陣列模擬罷工計算罷工天數,五六不罷工

待完成或

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

#include<iostream>#include<cstring>using namespace std; int days[3651]; int main(){ int cases,strike,period,numParty,t,count; cin >> cases; for(int i=0;i<cases;i++){ memset(days,0,sizeof(days)); count=0; cin >> period; cin >> numParty; for(int j=0;j<numParty;j++){ cin >> strike; t=strike; while(t<=period){ days[t]=1; t=t+strike; } } for(int j=1;j<=period;j++){ if ((days[j]==1)&&((j%7)!=6)&&((j%7)!=0)) count++; } cout << count <<endl; } }