Codeforces Round #701 (div.2)
A. Add and Devide
(solved)
Problem
Code
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int tc = 0;
vector<int> ans;
struct pos {
int count;
int a;
int b;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> tc;
while (tc--) {
int a, b;
cin >> a >> b;
int count = 0;
queue<pos> Q;
Q.push({ 0, a, b });
while (!Q.empty()) {
pos temp = Q.front();
Q.pop();
int& cnt = temp.count;
int& A = temp.a;
int& B = temp.b;
if (!(A / B)) {
ans.push_back(cnt + 1);
break;
}
Q.push({ cnt + 1, A / B, B });
Q.push({ cnt + 1, A, B + 1 });
}
}
for (auto e : ans) cout << e << '\n';
}
|
cs |
How to solve
BFS를 이용하여 구현하였다.
728x90
'Contests > Codeforces' 카테고리의 다른 글
Codeforces Round #703 (div.2) (0) | 2021.02.19 |
---|---|
Codeforces Round #699 (Div.2) A, B (0) | 2021.02.06 |
댓글