문제 링크입니다: www.acmicpc.net/problem/2991
2991번: 사나운 개
창영 마을의 우체부, 우유배달원, 신문배달원은 상근이네 집에 가는 것을 매우 싫어한다. 그 이유는 상근이네 집에는 사나운 개 두 마리가 지키고 있기 때문이다. 하지만, 그들은 이 개의 행동
www.acmicpc.net
간단한 수학 문제였습니다.
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 <iostream> | |
using namespace std; | |
bool gotAttacked(int time, int attack, int rest) | |
{ | |
return time % (attack + rest) <= attack && time % (attack + rest); | |
} | |
int getDogCnt(int time, int A, int B, int C, int D) | |
{ | |
return gotAttacked(time, A, B) + gotAttacked(time, C, D); | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int A, B, C, D; | |
int P, M, N; | |
cin >> A >> B >> C >> D >> P >> M >> N; | |
cout << getDogCnt(P, A, B, C, D) << "\n"; | |
cout << getDogCnt(M, A, B, C, D) << "\n"; | |
cout << getDogCnt(N, A, B, C, D) << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 6757번 팰린드롬 진법 (2) | 2021.05.13 |
---|---|
백준 2997번 네 번째 수 (4) | 2021.05.12 |
백준 2985번 세 수 (0) | 2021.05.10 |
백준 2975번 Transactions (0) | 2021.05.09 |
백준 2965번 캥거루 세마리 (0) | 2021.05.07 |