原題下載
答案:
#include <iostream>
#include <cstdlib>
using namespace std;
typedef long long ll;
int main() {
ll x, y;
cin >> x >> y;
ll ans = 0;
ll by = 1;
ll dir = 1;
while(true) {
// dir == 1 means Farmer John is moving to the right, and
// dir == -1 means he is moving to the left.
if((dir==1 && x<=y && y<=x+by) || (dir==-1 && x-by<=y && y<=x)) {
// We found Bessie!
ans += abs(y-x);
cout << ans << endl;
break;
} else {
// Didn't find Bessie! Add to our running total the cost of
// moving 'by' units away from the start and back again.
// Then multiply our next move's length by 2 and switch direction.
ans += by*2;
by *= 2;
dir *= -1;
}
}
}
以上就是關(guān)于【USACO 2017 US Open Contest, Bronze Problem 1. The Lost Cow】的解答,如需了解學(xué)校/賽事/課程動(dòng)態(tài),可至翰林教育官網(wǎng)獲取更多信息。
往期文章閱讀推薦:
NOAI人工智能奧賽 2026-2027 活動(dòng)章程出爐:新規(guī)則必看!
NOAI、UKOAI、USAAIO三大AI奧賽新賽季全面啟動(dòng):留學(xué)申請的“核武器”來了!

? 2026. All Rights Reserved. 滬ICP備2023009024號-1