Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16-kangrae-jo #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions kangrae-jo/BinarySearch/16-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <string>
#include <vector>

using namespace std;

int solution(vector<int> diffs, vector<int> times, long long limit) {
long long start = 0;
long long end = limit;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이진탐색을 ν†΅ν•΄μ„œ level을 μ°Ύμ•„κ°€λ‹ˆ endλŠ” level의 μ΅œλŒ“κ°’μΈ 100000이라고 μƒκ°ν•©λ‹ˆλ‹Ή

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ§€κΈˆ μƒκ°ν•΄λ³΄λ‹ˆ 이진탐색이 κ°€λŠ₯ν•œ μ΄μœ λŠ” if(time > limit)μ—μ„œ 퍼즐을 μ‹œκ°„λ‚΄μ— ν’€μˆ˜ μžˆλ”λΌλ„ μ΅œμ†Œ level을 κ΅¬ν•˜κΈ° μœ„ν•΄ e = m-1을 톡해 더 μž‘μ€ level을 톡해 퍼즐을 ν’€ 수 μžˆλŠ”μ§€ 계속 ν™•μΈν•˜λŠ” 둜직 λ•Œλ¬Έμ΄κ΅°μš”!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이진탐색을 ν†΅ν•΄μ„œ level을 μ°Ύμ•„κ°€λ‹ˆ endλŠ” level의 μ΅œλŒ“κ°’μΈ 100000이라고 μƒκ°ν•©λ‹ˆλ‹Ή

였 κ·Έλ ‡λ„€μš”! μˆœκ°„ limit λ³€μˆ˜μ˜ 의미λ₯Ό ν˜Όμš©ν•΄λ²„λ Έμ—ˆλ‚˜λ΄μš” κ°μ‚¬ν•©λ‹ˆλ‹€~

μ§€κΈˆ μƒκ°ν•΄λ³΄λ‹ˆ 이진탐색이 κ°€λŠ₯ν•œ μ΄μœ λŠ” if(time > limit)μ—μ„œ 퍼즐을 μ‹œκ°„λ‚΄μ— ν’€μˆ˜ μžˆλ”λΌλ„ μ΅œμ†Œ level을 κ΅¬ν•˜κΈ° μœ„ν•΄ e = m-1을 톡해 더 μž‘μ€ level을 톡해 퍼즐을 ν’€ 수 μžˆλŠ”μ§€ 계속 ν™•μΈν•˜λŠ” 둜직 λ•Œλ¬Έμ΄κ΅°μš”!

μ •ν™•νžˆ μ΄ν•΄λŠ” μ•ˆλ˜μ§€λ§Œ 그런 λŠλ‚Œμ€ λ§žμŠ΅λ‹ˆλ‹€. μƒν•œκ³Ό ν•˜ν•œμ„ 계속 μ‘°μ ˆν•˜λ©° μ΅œμ†Œ level을 μ°ΎλŠ” μ›λ¦¬μž…λ‹ˆλ‹€!

long long level;

while (1){
long long time = 0;

level = (start + end) / 2;
if (start > end) break;

for (int i = 0; i < diffs.size(); i++){
long long prev = level - diffs[i];
if (prev < 0) time += -prev * (times[i-1] + times[i]);
time += times[i];
}

if (time > limit) start = level + 1;
else if (time <= limit) end = level - 1;
}

return level + 1;
}
1 change: 1 addition & 0 deletions kangrae-jo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
| 11μ°¨μ‹œ | 2024.12.21 | Greedy | [ATM](https://www.acmicpc.net/problem/11399)|[#41](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/41)|
| 12μ°¨μ‹œ | 2024.12.24 | HEAP | [크리슀마슀 μ„ λ¬Ό](https://www.acmicpc.net/problem/14235)|[#44](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/44)|
| 13μ°¨μ‹œ | 2024.12.28 | Graph | [쀄 μ„Έμš°κΈ°](https://www.acmicpc.net/problem/2252)|[#46](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/46)|
| 16μ°¨μ‹œ | 2024.1.14 | BinarySearch | [퍼즐 κ²Œμž„ μ±Œλ¦°μ§€](https://school.programmers.co.kr/learn/courses/30/lessons/340212)|[#59](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/59)|

---
Loading