RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0279 파일 입출력

The Lost Cow

Bronze II 브론즈 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Farmer John has lost his prize cow Bessie, and he needs to find her!

Fortunately, there is only one long path running across the farm, and Farmer
John knows that Bessie has to be at some location on this path. If we think of
the path as a number line, then Farmer John is currently at position \(x\) and
Bessie is currently at position \(y\) (unknown to Farmer John). If Farmer John
only knew where Bessie was located, he could walk directly to her, traveling a
distance of \(|x - y|\). Unfortunately, it is dark outside and Farmer John can't
see anything. The only way he can find Bessie is to walk back and forth until
he eventually reaches her position.

Trying to figure out the best strategy for walking back and forth in his search,
Farmer John consults the computer science research literature and is
somewhat amused to find that this exact problem has not only been studied by
computer scientists in the past, but that it is actually called the "Lost Cow
Problem" (this is actually true!).

The recommended solution for Farmer John to find Bessie is to move to position
\(x+1\), then reverse direction and move to position \(x-2\), then to position
\(x+4\), and so on, in a "zig zag" pattern, each step moving twice as far from
his initial starting position as before. As he has read during his study of algorithms
for solving the lost cow problem, this approach guarantees that he will at worst
travel 9 times the direct distance \(|x-y|\) between himself and Bessie before he
finds her (this is also true, and the factor of 9 is actually the smallest such
worst case guarantee any strategy can achieve).

Farmer John is curious to verify this result. Given \(x\) and \(y\), please compute
the total distance he will travel according to the zig-zag search strategy above
until he finds Bessie.

Problem credits: Brian Dean

제약

Problem credits: Brian Dean

입력 형식

The single line of input contains two distinct space-separated integers \(x\) and
\(y\). Both are in the range \(0 \ldots 1,000\).

출력 형식

Print one line of output, containing the distance Farmer John will travel to
reach Bessie.

파일 입력 / 출력
이 문제는 표준 입출력을 사용하지 않습니다. 프로그램은 다음 파일을 읽고 써야 합니다:
입력을 읽을 파일 lostcow.in
출력을 쓸 파일 lostcow.out
예제 1
입력
3 6
출력
9
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2016-2017 > US Open > Bronze

태그

평가 및 의견

The Lost Cow

개요
출제자 난이도 Bronze II 브론즈 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

The Lost Cow

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8