문제 링크입니다: https://www.acmicpc.net/problem/4655
4655번: Hangover
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the
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; | |
int getCardCnt(double c) | |
{ | |
double sum = 0.00; | |
for (int i = 1; ;i++) | |
{ | |
sum += (1 / (double)(i + 1)); | |
if (sum >= c) | |
{ | |
return i; | |
} | |
} | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
while (1) | |
{ | |
double c; | |
cin >> c; | |
if (c == 0.00) | |
{ | |
break; | |
} | |
cout << getCardCnt(c) << " card(s)\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 4714번 Lunacy (0) | 2021.05.16 |
---|---|
백준 4690번 완전 세제곱 (0) | 2021.05.16 |
백준 4635번 Speed Limit (0) | 2021.05.16 |
백준 4623번 Copier Reduction (0) | 2021.05.16 |
백준 4619번 루트 (0) | 2021.05.15 |