4696번: St. Ives
Input consists of multiple data sets. Each data set consists of a line with a single floating point number number representing the numbers of wives, sacks per wife, cats per sack, and kittens per cat that Robert encountered that year. End of input is indic
www.acmicpc.net
power
- 제목
St. Ives
- 조건
시간 제한 : 1 초
메모리 제한 : 128 MB
- 문제
Robert the chapman (a medieval traveling merchant) made regular trips between his home village and St. Ives to peddle his cloth, ribbons, and needles. On one such trip he encountered a curious procession:
As I was traveling to St. Ives
I met a man with seven wives.
Every wife had seven sacks.
Every sack had seven cats.
Every cat had seven kits.
Kits, cats, sacks, wives -
How many were traveling to St. Ives?
The answer to this classic ancient riddle is ’one’. Robert was traveling to St. Ives. The others were all traveling away from St. Ives. However, if we prefer to ask the question of how many were traveling from St. Ives, we can add up:
- 1 man
- 7 wives
- 7*7 sacks
- 7*7*7 cats
- 7*7*7*7 kittens
for a total of 2801.
On his next trip to St. Ives, Robert met the same man, this time accompanied by 3 wives, each
with 3 sacks, and so on. Becoming curious about what seemed to be a bizarre village ritual of some kind, Robert kept track of how many traveled with the man each time he encountered him during the subsequent year.
On average, what was the size of the processions that Robert encounter on his trips to St. Ives?
- 입력
Input consists of multiple data sets. Each data set consists of a line with a single floating point number number representing the numbers of wives, sacks per wife, cats per sack, and kittens per cat that Robert encountered that year.
End of input is indicated by a value of zero.
- 출력
For each data set, print the size of the average procession as a real number presented to 2 decimal points precision.
예제 입력1 | 예제 출력1 |
7 1 2.5 0 |
2801.00 5.00 64.44 |
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define endl '\n'
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << fixed;
cout.precision(2);
double person;
while(true){
cin >> person;
if(person == 0) break;
double sum = 0;
for(int n = 0 ; n < 5 ; n++) sum += pow(person, n);
cout << sum << endl;
}
return 0;
}
'Problem Solving > BaekJoon' 카테고리의 다른 글
[BOJ/백준] 25494 - 단순한 문제 (Small) (0) | 2022.08.23 |
---|---|
[BOJ/백준] 23806 - 골뱅이 찍기 - ㅁ (0) | 2022.08.23 |
[BOJ/백준] 1620 - 나는야 포켓몬 마스터 이다솜 (0) | 2022.08.21 |
[BOJ/백준] 1764 - 듣보잡 (0) | 2022.08.20 |
[BOJ/백준] 2805 - 나무 자르기 (0) | 2022.08.20 |