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
- 트리
- BFS
- 알고리즘
- 백트래킹
- XR Interaction Toolkit
- 다이나믹 프로그래밍
- 시뮬레이션
- 그리디 알고리즘
- 스택
- DFS
- 유니온 파인드
- 구현
- 누적 합
- 수학
- 정렬
- 브루트포스
- 다익스트라
- 백준
- 재귀
- 자료구조
- Unreal Engine 5
- 그래프
- 유니티
- 투 포인터
- ue5
- VR
- Team Fortress 2
- 문자열
- 우선순위 큐
- c++
Archives
- Today
- Total
1일1알
백준 17451번 평행 우주 C++ 본문
https://www.acmicpc.net/problem/17451
17451번: 평행 우주
행성 1에 가기 위해 필요한 것보다 세 배의 속도로, 행성 2의 경우 두 배의 속도로 이동하면, 지구에서는 900의 속도만 쌓으면 된다.
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;
int64 n;
vector<int64> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
v = vector<int64>(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int64 ans = 0;
for (int i = n - 1; i >= 0; i--) {
if (v[i] >= ans) {
ans = v[i];
}
else {
if (ans % v[i] == 0) continue;
ans = ((ans / v[i]) + 1) * v[i];
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 20310번 타노스 C++ (0) | 2023.01.15 |
---|---|
백준 17141번 연구소 2 C++ (0) | 2023.01.14 |
백준 2660번 회장뽑기 C++ (0) | 2023.01.12 |
백준 11663번 선분 위의 점 C++ (0) | 2023.01.11 |
백준 18115번 카드 놓기 C++ (0) | 2023.01.10 |