chokudaiさんが毎日一問問題を選んでくれる #chokudai今日の一問
4日目は
今日の一問は、ARC001より、リモコン!AtCoderはここから始まった。
— chokudai(高橋 直大)🍆🍡🌸 (@chokudai) August 22, 2019
今の基準だと簡単目の300点くらいかな?解くことは出来るだろうけど、「5分で解いて」ってなると水色レベル。早解きを意識してやってみよう!https://t.co/z4G3AIGT7z#chokudai今日の一問
ARC#001 B. リモコン
解答. 前回はRubyで解いていた.
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <string> using namespace std; static int A, B; typedef pair<int, int> P; int bfs() { queue<P> que; que.push(P(A, 0)); P p; while (!que.empty()) { p = que.front(); que.pop(); if (p.first == B) { break; } for (int d : {-1, 1, -5, 5, -10, 10}) { if (abs(p.first + d - B) < abs(p.first - B)) { que.push(P(p.first + d, p.second + 1)); } } } return p.second; } void solve() { cout << bfs() << endl; } int main() { cin >> A >> B; solve(); return 0; }