문제 링크: https://www.acmicpc.net/problem/14530
14530번: The Lost Cow
The single line of input contains two distinct space-separated integers \(x\) and \(y\). Both are in the range \(0 \ldots 1,000\).
www.acmicpc.net
문제에서 최대 시작점과 도착점 사이의 거리의 9배만큼 걸린다고 했고, 시작점과 도착점 모두 0 부터 1000 사이의 값이므로, 실제 도착점에 도착할때까지 시뮬레이션으로 돌림.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <bits/stdc++.h>
using namespace std;
int x, y;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> x >> y;
int ans = 0, cur = x;
int two = 1, dir = 1;
while(1) {
while(1) {
if(cur == y) {
cout << ans << '\n';
return 0;
}
if(cur == x + dir * two) break;
ans++;
cur += dir;
}
dir *= -1;
two *= 2;
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Bronze' 카테고리의 다른 글
백준 15463 Blocked Billboard (USACO December 2017 Bronze 1번) (0) | 2020.03.03 |
---|---|
백준 14531 Bovine Genomics (USACO US Open 2017 Bronze 2번) (0) | 2020.03.01 |
백준 14469 소가 길을 건너간 이유 3 (USACO February 2017 Bronze 3번) (0) | 2020.03.01 |
백준 14468 소가 길을 건너간 이유 2 (USACO February 2017 Bronze 2번) (0) | 2020.02.29 |
백준 14467 소가 길을 건너간 이유 1 (USACO February 2017 Bronze 1번) (0) | 2020.02.29 |