알고리즘/BOJ

백준 9182번 Biorhythms

꾸준함. 2021. 7. 1. 00:17

문제 링크입니다: https://www.acmicpc.net/problem/9182

 

9182번: Biorhythms

You will be given a number of cases. The input for each case consists of one line of four integers (p, e, i, and d) separated by spaces. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional,

www.acmicpc.net

출력형식을 확인하자...

 

#include <iostream>
using namespace std;
const int MAX = 21252;
const int PHYSICAL_MOD = 23;
const int EMOTIONAL_MOD = 28;
const int INTELLECTUAL_MOD = 33;
const int MIN_PHYSICAL_OVER_YEAR = 23 * 16;
const int MIN_EMOTIONAL_OVER_YEAR = 28 * 14;
const int MIN_INTELLECTUAL_OVER_YEAR = 33 * 12;
int main(void)
{
for (int day = 1; ; day++)
{
int p, e, i, d;
cin >> p >> e >> i >> d;
if (p == -1 && e == -1 && i == -1 && d == -1)
{
break;
}
p = (p + (MIN_PHYSICAL_OVER_YEAR - d)) % PHYSICAL_MOD;
e = (e + (MIN_EMOTIONAL_OVER_YEAR - d)) % EMOTIONAL_MOD;
i = (i + (MIN_INTELLECTUAL_OVER_YEAR - d)) % INTELLECTUAL_MOD;
int visited[MAX + 1] = { 0, };
for (int idx = p; idx <= MAX; idx += PHYSICAL_MOD)
{
visited[idx]++;
}
for (int idx = e; idx <= MAX; idx += EMOTIONAL_MOD)
{
visited[idx]++;
}
for (int idx = i; idx <= MAX; idx += INTELLECTUAL_MOD)
{
visited[idx]++;
}
int result = 1;
for (int idx = 1; idx <= MAX; idx++)
{
if (visited[idx] == 3)
{
result = idx;
break;
}
}
printf("Case %d: the next triple peak occurs in %d days.\n", day, result);
}
return 0;
}
view raw .cpp hosted with ❤ by GitHub

 

개발환경:Visual Studio 2017

 

지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 9286번 Gradabase  (0) 2021.07.03
백준 9228번 Check Digits  (0) 2021.07.02
백준 9161번 Sir Bedavere's Bogus Division Solutions  (0) 2021.06.28
백준 9151번 Starship Hakodate-maru  (0) 2021.06.28
백준 9094번 수학적 호기심  (0) 2021.06.28