-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0403-5.cpp
More file actions
37 lines (34 loc) · 836 Bytes
/
0403-5.cpp
File metadata and controls
37 lines (34 loc) · 836 Bytes
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
31
32
33
34
35
36
37
#include <string>
#include <vector>
#include <queue>
using namespace std;
int solution(int storey) {
int answer = 100000000;
queue<pair<int, int>> q;
q.push(make_pair(storey, 0));
while(!q.empty())
{
int current = q.front().first, cost = q.front().second;
q.pop();
printf("cur: %d, cost: %d\n", current, cost);
if(current < 0) continue;
if(current == 0)
{
answer = min(answer, cost);
continue;
}
if(current % 10 == 0)
{
q.push(make_pair(current / 10, cost));
continue;
}
int left = current % 10;
q.push(make_pair(current - left, cost + left));
q.push(make_pair(current + 10 - left, cost + 10 - left));
}
return answer;
}
int main()
{
solution(16);
}