코딩/BOJ & 알고스팟
[BOJ 1459] 걷기
hoon222y
2017. 10. 5. 23:50
https://www.acmicpc.net/problem/1459
단순하게 생각해서 풀면된다. 주의해야 할 점은 대각선을 이용해서 갈때 더 가까워지는 지점이 있다는 점과 ... 자료형 int범위 벗어난다는 것이다 ;
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 | #include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <algorithm> #include <cstring> #include <set> #include <queue> typedef long long ll; using namespace std; ll x,y,c,d; int main(){ cin >>x >> y>>c >>d; if(x>y) swap(x, y); ll ans = min((x+y)*c , x*d+(y-x)*c); if((y-x)%2 == 1){ ans= min(ans , (y-1)*d +c); }else{ ans = min(ans , y*d); } cout <<ans <<endl; } | cs |