題意:
每個政黨都有發表演講的週期,只要星期日~星期四該天有任何一個政黨演講,hartal數目就+1,最後輸出hartal。
想法:
日數從1開始,每天對每個政黨的週期取餘數,若為0代表該日那個政黨有演講,hartal++。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
using namespace std; | |
int main() | |
{ | |
int T,N,P,h[101]; // T: number of cases, N: number of days | |
// P: number of parties, h[i]: hartal parameter for party i | |
scanf("%d",&T); | |
while (T--) | |
{ | |
scanf("%d%d",&N,&P); | |
for (int i=0; i<P; i++) scanf("%d",&h[i]); | |
int hartal=0; | |
for (int i=1; i<=N; i++){ | |
if (i%7 == 6) { // 跳過星期五和星期六 | |
i++; continue; | |
} | |
for (int j=0; j<P; j++){ | |
if (i%h[j] == 0) { | |
hartal++; | |
break; | |
} | |
} | |
} | |
printf("%d\n",hartal); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言