※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 13228번 문제인 The REAL Manhattan distance이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/13228
13228번: The REAL Manhattan distance
The first line will contain the number of test cases T. Each of the next T lines will contain 2 points. You have to compute the distance between these two points. Each test cases is a line with 6 integer numbers x1, y1, floor1, x2, y2, floor2. See the exam
www.acmicpc.net
문제에서 요구하는 거리는 (1) 출발지점의 아파트에서 지상으로 내려오는 거리와 (2) 두 아파트의 (지상기준) 맨해튼거리와 (3) 도착지점의 아파트로 지상에서 올라가는 거리의 합으로 구할 수 있다.
위의 각 값의 합을 구해 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int x1, y1, f1, x2, y2, f2;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T; cin >> T;
while (T--) {
cin >> x1 >> y1 >> f1 >> x2 >> y2 >> f2;
cout << abs(x1 - x2) + abs(y1 - y2) + f1 + f2 << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 25759 // C++] 들판 건너가기 (0) | 2022.11.27 |
---|---|
[BOJ 13234 // C++] George Boole (0) | 2022.11.27 |
[BOJ 13236 // C++] Collatz Conjecture (0) | 2022.11.27 |
[BOJ 13235 // C++] 팰린드롬 (0) | 2022.11.27 |
[BOJ 13227 // C++] TicTacToe (0) | 2022.11.26 |