문제 이해 했고 문제 적힌 그대로 구현했다.
a != b일동안 while 돌고 내부에서는 10부터 1까지 빼는데 이전 값이랑 다르거나 뺀 결과가 b보다 크거나 같을 때까지 뺐다.
그런데 결과가 조금 다르다...? 이 때 1차 디용했고 다음으로 이렇게 풀면 시간 복잡도 터지니깐 다른 방법 생각했다.
다음 방법.. 가장 최소로 만드려면 가장 큰 수를 빼야 하는데 가장 큰 수는 10 - 9 - 10 - 9로 이어진다. 그래서 19를 계속 빼면 되겠다 싶어서 먼저 19로 나누고 다음으로 나머지 수의 횟수를 더하면 되겠다 싶었다.
나머지 횟수는 위와 같다.
ㅋㅋㅋ그런데 예시랑 답이 다르다.. 내 답이 더 작게 나옴... 19씩 나누면 되잖아... 뭐가 문제인지 모르겠음
tlqk..
may가 다른 거 써도 된다는 거였음
저 different에 집중해서 몰랐네 으으으.. 으!
아 그리고 답이 더 작게 나왔던건 내가 * 2를 안 해서 그랬다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;
void solve()
{
i64 a, b;
scanf("%lld %lld", &a, &b);
if (b > a)
swap(a, b);
i64 move = (a - b) / 10;
if ((a - b) % 10 != 0)
move++;
printf("%lld\n", move);
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
solve();
}
return 0;
}
'코드포스' 카테고리의 다른 글
[코드포스 Round 667] C. Yet Another Array Restoration (0) | 2020.11.12 |
---|---|
[코드포스 Round 667] B. Minimum Product (0) | 2020.11.12 |
[코드포스 Round 667] 후기 (0) | 2020.11.12 |
[코드포스 Round 677] E. Two Round Dances (0) | 2020.11.07 |
[코드포스 Round 677] D. Districts Connection (0) | 2020.11.07 |