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 |
29 | 30 | 31 |
Tags
- NRVO
- softeer
- RootMotion
- UE5
- UnrealEngine4
- 1563
- 티스토리챌린지
- UnrealEngine5
- const
- algorithm
- 언리얼엔진5
- GeeksForGeeks
- DirectX11
- 프로그래머스
- Frustum
- Programmers
- baekjoon
- C
- IFileDialog
- 줄 세우기
- RVO
- C++
- 팰린드롬 만들기
- winapi
- 백준
- 2294
- 오블완
- Unreal Engine5
- DeferredRendering
- directx
Archives
- Today
- Total
Game Develop
[Algorithm] Programmers :: 우박수열 정적분 본문
https://school.programmers.co.kr/learn/courses/30/lessons/134239
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
|
vector<double> solution(int k, vector<vector<int>> ranges)
{
vector<double> answer;
vector<vector<int>> coordinates;
vector<double> areas = { 0 };
int count = 0;
coordinates.push_back({ 0,k });
while (k != 1)
{
if (k % 2 == 0) k /= 2;
else k = k * 3 + 1;
++count;
coordinates.push_back({ count,k });
}
double sum = 0;
for (int i = 1; i < coordinates.size(); ++i)
{
int leftX = coordinates[i - 1][0];
int leftY = coordinates[i - 1][1];
int rightX = coordinates[i][0];
int rightY = coordinates[i][1];
double boxArea = min(leftY, rightY) * (rightX - leftX);
double triangle = abs(rightY - leftY) * (rightX - leftX) / 2.0f;
sum += boxArea + triangle;
areas.push_back(sum);
}
int maxX = coordinates.size() - 1;
for (int i = 0; i < ranges.size(); ++i)
{
int leftX = ranges[i][0];
int rightX = maxX + ranges[i][1];
if (leftX > rightX) answer.push_back(-1);
else answer.push_back(areas[rightX] - areas[leftX]);
}
return answer;
}
|
cs |
'Algorithm > Programmers' 카테고리의 다른 글
[Algorithm] Programmers :: 귤 고르기 (0) | 2023.06.08 |
---|---|
[Algorithm] Programmers :: 숫자 카드 나누기 (0) | 2023.06.08 |
[Algorithm] Programmers :: 롤케이크 자르기 (0) | 2023.06.08 |
[Algorithm] Programmers :: 택배상자 (0) | 2023.06.08 |
[Algorithm] Programmers :: 연속 부분 수열 합의 개수 (0) | 2023.06.07 |