반응형
SMALL
문제 정보
문제명 - St. lves
난이도 - 브론즈 IV
문제 번호 - 4696번
문제 링크
https://www.acmicpc.net/problem/4696
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
문제
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.
예제 입력/출력
예제 입력 예제 출력 7 1 2.5 0
2801.00 5.00 64.44
알고리즘 분류
● 수학
● 사칙연산
소스코드
package Lv1_Bronze;
import java.io.*;
/**
* @author HanHoon
* @category 수학, 사칙연산
* https://www.acmicpc.net/problem/4696
*/
public class BOJ_B4_4696_St_lves {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while(true){
double n = Double.parseDouble(br.readLine());
if(n == 0)
break;
// 남자, 아내의 수, 아내당 자루 수, 자루당 고양이 수, 그해 로버트가 만난 고양이 수
System.out.printf("%.2f\n", 1 + n + n*n + n*n*n + n*n*n*n);
}
br.close();
}
}
BaekJoon List
BaekJoon List
BOJ Start!! ● [BOJ] 백준 회원가입, 시작하는 법 ● [BOJ] 등급(티어) 및 Solved.AC 적용 ● [BOJ/JAVA] 백준 소스코드 제출 시 유의사항(자바) Bronze ● Bronze V - ● Bronze IV - ● Bronze III -..
han-hoon.tistory.com
기회는 준비된 자에게 찾아온다.
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/014.gif)
반응형
LIST
'BaekJoon > Bronze' 카테고리의 다른 글
[BOJ/JAVA] 백준 1159 : 농구 경기 (자바) (0) | 2023.07.18 |
---|---|
[BOJ/JAVA] 백준 1547 : 공 (자바) (0) | 2023.07.17 |
[BOJ/JAVA] 백준 5341 : Pyramids (자바) (0) | 2023.07.15 |
[BOJ/JAVA] 백준 4589 : Gnome Sequencing (자바) (0) | 2023.07.14 |
[BOJ/JAVA] 백준 5339 : 콜센터 (자바) (0) | 2023.07.14 |
댓글