U E D R , A S I H C RSS

Hartals/문보창

소감

2005/03/31 Accepted 0:00.002 64
간단히 각 정당의 동맹휴업 날짜를 OR 연산하면 되는 문제다.
~cpp  
inline void init_days(bool * day, const int & N) { for (int i=1; i<=N; i++) day[i] = false; }; 
여기에서 i<=N 부분을 i

코드

~cpp 
// no10050 - Hartals
#include <iostream>
using namespace std;

const int MAX_DAY = 3651;				// 시뮬레이션을 돌릴 최대날짜

void make_red_day(bool * day, const int & P, const int & N);
void count_red_day(const bool * day, const int & N, int & red);

inline void input_N(int & N) { cin >> N; };
inline void input_P(int & P) { cin >> P; };
inline void init_days(bool * day, const int & N) { for (int i=1; i<=N; i++) day[i] = false; };
inline void show_red_day(const int & red) { cout << red << endl; };

int main()
{
	bool days[MAX_DAY];			// 동맹휴업여부	
	int nCase;	// Case의 개수
	int N;		// 시뮬레이션을 돌릴날짜
	int P;		// 정당의 개수
	int nRed;	// 휴업수
	
	cin >> nCase;
	
	int i;
	for (i=0; i<nCase; i++)
	{
		input_N(N);
		init_days(days, N);
		input_P(P);
		make_red_day(days, P, N);
		count_red_day(days, N, nRed);
		show_red_day(nRed);
	}
	return 0;
}

void make_red_day(bool * day, const int & P, const int & N)
{
	int i, j;
	int H;		// 동맹휴업지수
	for (i=0; i<P; i++)
	{
		cin >> H;
		for (j=H; j<=N; j += H) 
			day[j] = true;	
	}
}

void count_red_day(const bool * day, const int & N, int & red)
{
	red = 0;
	if (day[1])
		red++;
	int count = 0;
	for (int i=2; i<=N; i++)
	{
		count++;
		if (count%7 == 5)
		{
			count++;
			i++;
			continue;
		}
		if (day[i])
			red++;		
	}
}

나한테 할 말

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:22
Processing time 0.0222 sec