iT邦幫忙

2025 iThome 鐵人賽

DAY 18
0
自我挑戰組

cpe30天練習系列 第 18

cpe練習day18

  • 分享至 

  • xImage
  •  

今天是練習cpe的Hartals題目
##程式碼

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int T;
    cin >> T; 
    while(T--)
	{
    	int N, P, h;
    	cin >> N; 
		cin >> P;
    	int days[N+1]={};
		int total = 0;	
    	for (int i = 0 ;i < P ;i++) 
		{
    		cin >> h;
    		for (int j = h;j <= N ;j+=h) 
			{
    			if (j % 7 == 6 || j % 7 == 0)
    			{
    				continue;
				}
    			if (days[j] == 0) 
				{
    				total++;
    				days[j] = 1;
				}
			}
		}		
		cout << total << endl;
	}
	return 0;
}

解題方向

  • cin >> h; -> 政黨的罷工週期
  • for (int j = h; j <= N; j += h) -> 該政黨每隔h天罷工
  • if (j % 7 == 6 || j % 7 == 0) -> 如果星期五或星期六跳過
  • if (days[j] == 0) -> 如果這天還沒被算過
  • days[j] = 1; -> 標記這天已經算過

上一篇
cpe練習day17
下一篇
cpe練習day19
系列文
cpe30天練習19
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言