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

11-yuyu0830 #45

Merged
merged 1 commit into from
May 22, 2024
Merged

11-yuyu0830 #45

merged 1 commit into from
May 22, 2024

Conversation

yuyu0830
Copy link
Collaborator

@yuyu0830 yuyu0830 commented May 8, 2024

πŸ”— 문제 링크

μ—°λ£Œμ±„μš°κΈ°

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

20λΆ„

✨ μˆ˜λ„ μ½”λ“œ

❓ 문제

우리의 주인곡 μ„±κ²½μ΄λŠ” μˆ˜μ§μ„  μƒμ—μ„œ 0μ—μ„œ μΆœλ°œν•΄ LκΉŒμ§€ κ°€μ•Όν•œλ‹€. μ—°λ£Œκ°€ μ œν•œλ˜μ–΄μžˆκ³ , 쀑간쀑간 μ£Όμœ μ†Œκ°€ 있으며 μ£Όμœ μ†Œμ—μ„œ μ±„μšΈ 수 μžˆλŠ” μ—°λ£Œμ˜ 양은 μ •ν•΄μ Έμžˆλ‹€. μ£Όμœ μ†Œλ₯Ό μ΅œλŒ€ν•œ 적게 λ°©λ¬Έν•˜κ³  λͺ©ν‘œ μ§€μ κΉŒμ§€ 갈 수 μžˆλŠ” 방법을 μ°Ύμ•„λ³΄μž
μ£Όμœ μ†Œμ˜ 개수 n이 주어진닀. 이후 n개의 μ£Όμœ μ†Œ 정보가 μ£Όμ–΄μ§€λŠ”λ° μ‹œμž‘ 지점뢀터 μ£Όμœ μ†ŒκΉŒμ§€μ˜ μœ„μΉ˜ a, μ£Όμœ μ†Œμ—μ„œ 얻을 수 μžˆλŠ” μ—°λ£Œμ˜ λŸ‰ bκ°€ 주어진닀.
이후 λ§ˆμ§€λ§‰ 쀄에 λͺ©ν‘œ 지점 Lκ³Ό ν˜„μž¬ μ—°λ£Œ Pκ°€ 주어진닀.

❗ 풀이

μš°μ„ μˆœμœ„ 큐λ₯Ό μ΄μš©ν•˜λ©΄ μ‰½κ²Œ ν’€ 수 μžˆλŠ” λ¬Έμ œμ˜€λ‹€.

  1. ν˜„μž¬ 갈 수 μžˆλŠ” μ£Όμœ μ†Œλ₯Ό μš°μ„ μˆœμœ„ 큐에 λ„£λŠ”λ‹€. (μ—°λ£Œ λ§Žμ€ 순)
  2. κ°€μž₯ μ—°λ£Œλ₯Ό 많이 얻을 수 μžˆλŠ” μ£Όμœ μ†Œλ₯Ό λ°©λ¬Έν•œλ‹€. (μ—°λ£Œλ₯Ό μ–»λŠ”λ‹€)
  3. λͺ©μ μ§€ 도착 μ—¬λΆ€λ₯Ό μ²΄ν¬ν•œλ‹€. λ„μ°©ν–ˆλ‹€λ©΄ 탐색 μ’…λ£Œ
  4. λ„μ°©ν•˜μ§€ λͺ»ν–ˆλ‹€λ©΄ μΆ”κ°€λ‘œ 얻은 μ—°λ£Œλ§ŒνΌ λ”μš± 움직일 수 μžˆμœΌλ‹ˆ λ‹€μ‹œ 1λ²ˆλΆ€ν„° λ°˜λ³΅ν•œλ‹€.

νŠΉλ³„ν•œ μ˜ˆμ™Έ μΌ€μ΄μŠ€λ„ μ—†μ—ˆκ³  μš°μ„ μˆœμœ„ 큐λ₯Ό μ“°κ±°λ‚˜ μ •λ ¬λ§Œ ν•˜λ©΄ λ˜λŠ” 문제라 μ‰½κ²Œ ν’€λ Έλ˜ 것 κ°™λ‹€. 이게 κ³¨λ“œ 2..?

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

Copy link
Collaborator

@InSange InSange left a comment

Choose a reason for hiding this comment

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

μ–΄λ””μ„œ 많이 λ³Έ 문제 κ°™λ”λΌλ‹ˆ..
μ € 같은 κ²½μš°μ—λŠ”
ν˜„μž¬ 가지고 μžˆλŠ” μ—°λ£Œμ—μ„œ λ‹€μŒ λ§ˆμ„κΉŒμ§€μ˜ 거리λ₯Ό μ°¨κ·Όμ°¨κ·Ό λΉ„κ΅ν•΄λ‚΄κ°€λ©΄μ„œ ν–ˆκΈ°λ•Œλ¬Έμ— ꡳ이 μ—°λ£Œλ§ŒνΌ 값을 λΊ„ν•„μš”κ°€ μ—†μ—ˆμŠ΅λ‹ˆλ‹€!

int fuel = P;
	for (int i = 0; i < v.size(); i++)
	{
		if (fuel < v[i].first)
		{
			while (!pq.empty() && fuel < v[i].first)
			{
				fuel += pq.top();
				pq.pop();
				answer++;
			}
			if(fuel < v[i].first)	break;
		}
		//fuel += v[i].second;
		pq.push(v[i].second);
	}

Copy link
Collaborator

@seongwon030 seongwon030 left a comment

Choose a reason for hiding this comment

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

μš°μ„ μˆœμœ„ 큐둜 μ—°λ£Œκ°€ λ§Žμ€ 순으둜 μ •λ ¬ν•˜μ—¬ λ§Žμ€ 것뢀터 ν™•μΈν•˜λ©΄μ„œ λ°©λ¬Έμ—¬λΆ€λ₯Ό μ²΄ν¬ν•˜λ©΄ λ˜λŠ”κ΅°μš”. μž¬κ·€λ₯Ό μƒκ°ν–ˆμ„ λ•ŒλŠ” λΆˆν•„μš”ν•œ 뢀뢄도 λ‹€ 검사λ₯Ό ν•΄μ•Όν•˜κΈ° λ•Œλ¬Έμ— 닡이 없을 것 κ°™λ”λΌκ³ μš”. νŒŒμ΄μ¬μ—μ„  heap 을 μ‚¬μš©ν•΄μ„œ μ§€λ‚˜κ°„ μ£Όμœ μ†Œμ—μ„œ μ±„μšΈ 수 μžˆλŠ” μ£Όμœ λŸ‰μ„ λ¦¬μŠ€νŠΈμ— μ €μž₯ν•˜κ³  κΊΌλ‚΄λŠ” λ°©μ‹μœΌλ‘œ ν•©λ‹ˆλ‹€.
νž™μ€ μž‘μ€ μž‘μ€ μˆ«μžκ°€ μœ„λ‘œ κ°€κΈ° λ•Œλ¬Έμ— -λ₯Ό λΆ™μ—¬ 큰 값을 항상 꺼내도둝 λ§Œλ“€μ—ˆμ–΄μš”.

Copy link
Contributor

@dhlee777 dhlee777 left a comment

Choose a reason for hiding this comment

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

λ‘κ°œμ˜ μš°μ„ μˆœμœ„νλ₯Ό μ‚¬μš©ν•˜μ—¬ ν•˜λ‚˜λŠ” 거리순으둜 μ •λ ¬ν•˜κ³  ν•˜λ‚˜λŠ” λ§Žμ€μ—°λ£Œλ₯Όμ œκ³΅ν•΄μ£ΌλŠ” μ£Όμœ μ†Œ 순으둜 μ •λ ¬ν•˜μ—¬ μ΅œμ†Œμ˜ 방문횟수λ₯Ό μ°Ύμ•„λ‚΄λŠ” κ±°κ΅°μš” κΉ”λ”ν•œμ½”λ“œ μž˜λ³΄μ•˜μŠ΅λ‹ˆλ‹€..!

@yuyu0830 yuyu0830 merged commit 973e3d5 into main May 22, 2024
1 check passed
@yuyu0830 yuyu0830 deleted the 11-yuyu0830 branch May 22, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants