Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- DFS
- 구현
- c++
- 다이나믹 프로그래밍
- 문자열
- Team Fortress 2
- 브루트포스
- 백트래킹
- 우선순위 큐
- 재귀
- 알고리즘
- 유니온 파인드
- XR Interaction Toolkit
- VR
- 트리
- 투 포인터
- 정렬
- 유니티
- 자료구조
- 누적 합
- 수학
- 시뮬레이션
- BFS
- 다익스트라
- 그래프
- 스택
- 그리디 알고리즘
- Unreal Engine 5
- ue5
- 백준
Archives
- Today
- Total
1일1알
백준 10655번 마라톤 1 C++ 본문
https://www.acmicpc.net/problem/10655
10655번: 마라톤 1
젖소 박승원은 2번째 혹은 3번째 체크포인트를 건너뛸 수 있는데, 여기서 두 번째 체크포인트를 건너뛸 경우 경로는 (0,0) -> (11,-1) -> (10,0) 이 되며 거리는 14이다. 박승원은 이것보다 더 짧게 달릴
www.acmicpc.net
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
int64 totalDist = 0;
vector<pair<int, int>> v;
vector<int64> dists;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
v = vector<pair<int, int>>(n);
dists = vector<int64>(n);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
v[i] = { x,y };
}
for (int i = 1; i < n; i++) {
int64 dist = abs(v[i - 1].first - v[i].first) + abs(v[i - 1].second - v[i].second);
dists[i] = dist;
totalDist += dist;
}
int64 ans = totalDist;
for (int i = 1; i < n - 1; i++) {
int64 dist1 = dists[i] + dists[i + 1];
int64 dist2 = abs(v[i - 1].first - v[i + 1].first) + abs(v[i - 1].second - v[i + 1].second);
int sub = dist1 - dist2;
ans = min(ans, totalDist - sub);
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 11441번 합 구하기 C++ (0) | 2023.04.15 |
---|---|
백준 3967번 매직 스타 C++ (0) | 2023.04.14 |
백준 9081번 단어 맞추기 C++ (0) | 2023.04.07 |
백준 11504번 돌려 돌려 돌림판! C++ (0) | 2023.04.06 |
백준 15787번 기차가 어둠을 헤치고 은하수를 C++ (0) | 2023.04.05 |