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

82-tgyuuAn #257

Merged
merged 2 commits into from
Dec 1, 2024
Merged

82-tgyuuAn #257

merged 2 commits into from
Dec 1, 2024

Conversation

tgyuuAn
Copy link
Member

@tgyuuAn tgyuuAn commented Nov 20, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

ํ•ฉ์„ฑํ•จ์ˆ˜์™€ ์ฟผ๋ฆฌ

(๋งˆ์ด๋„ˆํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ๋“ค์–ด๊ฐ€์„œ ์กฐ๊ธˆ๋งŒ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๊ณ  ์•ˆ๋˜๋ฉด ๋ฐ”๋กœ ํ”ผ์•Œ ์ฝ์–ด์š”!)

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

1์‹œ๊ฐ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ฌธ์ œ๋Š” ์™„์ „ ๊ฐ„๋‹จ!

fn(x) = f ( fn-1(x) ) ๊ฐ€ ๋˜๋Š”๋ฐ,

n๊ณผ x๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ์ด๋ฅผ ๊ตฌํ•˜๋ฉด ๋œ๋‹ค.




์ด ๋•Œ, 1 <= n, x <= 500,000 ์ด๊ณ ,

์ฟผ๋ฆฌ์˜ ๊ฐœ์ˆ˜ Q <= 200,000 ์ด๋‹ค.




๋งŒ์•ฝ, ์ด ๋ฌธ์ œ๋ฅผ ์™„ํƒ์œผ๋กœ ํ’€๋ ค๊ณ  ํ–ˆ๋‹ค๋ฉด,

20๋งŒ๊ฐœ์˜ ์ฟผ๋ฆฌ๋ฅผ 50๋งŒ๋ฒˆ ์—ฐ์‚ฐ์„ ํ•ด์•ผํ•˜๋ฏ€๋กœ

$200,000 * 500,000 = 10,000,000,000,000$ ๋กœ ๋ฌด์ €ใ…“ใ…“ใ…“ใ…“ใ…“ใ…“๊ฟ˜ ํƒ€์ž„์˜ค๋ฐ”๊ฐ€ ๋‚œ๋‹ค.




๊ทธ๋ž˜์„œ ์ด ๋ฌธ์ œ๋ฅผ ํ’€๋ ค๋ฉด ๋ฌด์Šจ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์•Œ์•„์•ผ ํ•˜๋Š๋ƒ?

๊ทธ๊ฒƒ์€ ๋ฐ”๋กœ ๋‚˜๋„ ์ฒ˜์Œ ๋“ค์–ด๋ณธ ํฌ์†Œ ๋ฐฐ์—ด ์ด์—ˆ๋‹ค.

์‚ฌ์‹ค ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ชฐ๋ผ๋„ ์™ ๋งŒํ•œ ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ํ†ต๊ณผํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ทผ๋ฐ ์ด๋Ÿฐ๊ฒŒ ์žˆ๋”๋ผ ..




ํฌ์†Œ ๋ฐฐ์—ด์ด๋ž€,

์•„๋ž˜์™€ ๊ฐ™์€ ๊ทธ๋ž˜ํ”„๊ฐ€ ์žˆ์„ ๋•Œ,

image

๊ฐ ๋…ธ๋“œ์—์„œ ํ™”์‚ดํ‘œ๋ฅผ ๋”ฐ๋ผ 1๋ฒˆ ์ด๋™ ํ–ˆ์„ ๋•Œ์˜ ๋…ธ๋“œ๋Š” ์•„๋ž˜ ํ‘œ์™€ ๊ฐ™๋‹ค.

image




๊ทธ๋Ÿผ 2๋ฒˆ, 3๋ฒˆ ์ด๋™ํ–ˆ์„ ๋•Œ์˜ ํ‘œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์„ ๊ฒƒ์ด๋‹ค.

image




๊ทธ๋Ÿผ ๋งŒ์•ฝ 2๋ฒˆ ๋…ธ๋“œ์—์„œ 30๋ฒˆ ์ด๋™ํ–ˆ์„ ๋•Œ์˜ ๋…ธ๋“œ๋Š” ์–ด๋–ป๊ฒŒ ๊ตฌํ•˜๊ฒ ๋Š”๊ฐ€ ..?

image

์›๋ž˜๋ผ๋ฉด 2๋ฒˆ ๋…ธ๋“œ์—์„œ 30๋ฒˆ ์ญ‰์ญ‰ ๋ป—์–ด๋ด์•ผ ํ•  ๊ฒƒ์ด๋‹ค.

์ด๋Ÿด ๊ฒฝ์šฐ ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” O(1) ์ด๋‹ค.




์ด๋ฅผ ๋” ๋‹จ์ถ• ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์€ ์—†์„๊นŒ?




์ž˜ ์ƒ๊ฐํ•ด๋ณด๋ฉด ๊ฐ ๋…ธ๋“œ์—์„œ 2๋ฒˆ ์ด๋™ํ•œ ๋…ธ๋“œ๋Š”,

1๋ฒˆ ์ด๋™ํ•œ ๋…ธ๋“œ์—์„œ ํ•œ ๋ฒˆ ๋” ๋‚˜์•„๊ฐ„ ๋…ธ๋“œ์ด๋‹ค.




๊ทธ๋ฆฌ๊ณ  2๋ฒˆ ๋…ธ๋“œ์—์„œ 4๋ฒˆ ์ด๋™ํ•œ ๋…ธ๋“œ๋Š”,

2๋ฒˆ ๋…ธ๋“œ์—์„œ 2๋ฒˆ ์ด๋™ํ•œ ๋…ธ๋“œ์˜ ๊ฐ’์„, (์œ„ ์˜ˆ์‹œ์—์„œ๋Š” 6)

2๋ฒˆ ์ด๋™ํ•œ ๋…ธ๋“œ์˜ ํ‘œ์— ๋Œ€์ž…ํ•˜๋ฉด ๋œ๋‹ค. (2๋ฒˆ ์ด๋™ํ•œ ํ‘œ์˜ ๊ฐ’์— 6์„ ๋„ฃ์œผ๋ฉด 5์ด๋‹ค.)

image




๋งˆ์ฐฌ๊ฐ€์ง€๋กœ, 2๋ฒˆ ๋…ธ๋“œ์—์„œ 8๋ฒˆ ์ด๋™ํ•œ ๋…ธ๋“œ๋Š”

2๋ฒˆ ๋…ธ๋“œ์—์„œ 4๋ฒˆ ์ด๋™ํ•œ ๋…ธ๋“œ์˜ ๊ฐ’์„, (์œ„ ์˜ˆ์‹œ์—์„œ๋Š” ๋ฐฉ๊ธˆ๊ตฌํ–ˆ๋˜ ๊ฒƒ ์ฒ˜๋Ÿผ 5์ด๋‹ค.)

4๋ฒˆ ์ด๋™ํ•œ ๋…ธ๋“œ์˜ ํ‘œ๋ฅผ ๊ตฌํ•œ๋‹ค์Œ ๋Œ€์ž…ํ•˜๋ฉด ๋˜ ๋‚˜์˜จ๋‹ค. (์œ„ ์˜ˆ์‹œ์—์„œ๋Š” 4๊ฐ€ ๋‚˜์˜ฌ ๊ฒƒ์ด๋‹ค.)




์ฆ‰, ์ด๋Ÿฐ ์‹์œผ๋กœ 1 -> 2-> 4-> 8 -> 16 -> ... ์ฒ˜๋Ÿผ 2๋ฐฐ์ˆ˜๋กœ ์ด๋™ํ–ˆ์„ ๋•Œ์˜ ํ‘œ ๊ฐ’๋งŒ ๊ธฐ์–ตํ•˜๋ฉด ๋ฌด์—‡์ด๋“  ์†์‰ฝ๊ฒŒ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค๋ฉด 2๋ฒˆ 13๋ฒˆ ์ด๋™ํ–ˆ์„ ๋•Œ์˜ ๊ฐ’์„ ๊ตฌํ•ด๋ณด์ž.

์ด๋Š” 2๋ฒˆ ๋…ธ๋“œ์—์„œ 8๋ฒˆ ์ด๋™ํ–ˆ์„ ๋•Œ์˜ ๊ฐ’์„ 4๋ฒˆ ์ด๋™ํ–ˆ์„ ๋•Œ์˜ ํ‘œ์— ๋„ฃ์€ ๋‹ค์Œ,

์œ„์—์„œ ๊ตฌํ•œ ๊ฐ’์„ 1๋ฒˆ ์ด๋™ํ–ˆ์„ ๋•Œ์˜ ํ‘œ์— ๋„ฃ์œผ๋ฉด ๋‚˜์˜จ๋‹ค.

์ฆ‰, f1( f4( f8(2) ) ) ๊ฐ€ ๋˜๋Š” ๊ฒƒ์ด๋‹ค!!!




์ž ์œ„์˜ ๊ฐœ๋…์„ ์ด์šฉํ•˜๋ฉด n์ด 50๋งŒ์ด๋”๋ผ๋„ log(50๋งŒ) ๋ฒˆ์˜ ์—ฐ์‚ฐ๋งŒ ๊ฐ’์„ ์ผ€์‹ฑํ•ด๋†“์œผ๋ฉด ๋˜๋ฏ€๋กœ,

log(1000) + log(500) = 10 + 9 = 19 ๋ฒˆ์˜ ์—ฐ์‚ฐ๋งŒ ์ง„ํ–‰ํ•˜๋ฉด ๋œ๋‹ค.




์œ„ ๊ฐœ๋…์„ ์ด ๋ฌธ์ œ์—์„œ ์–ด๋–ป๊ฒŒ ์จ๋จน์„ ์ˆ˜ ์žˆ์„๊นŒ?

์•„๋ž˜ ๋ฌธ์ œ๋ฅผ ํ•œ๋ฒˆ ์ž˜ ๋“ค์—ฌ๋‹ค๋ณด์ž.

image




f4(x)์˜ ๊ฒฝ์šฐ๋Š” f(x)๋ฅผ 4๋ฒˆ ์ง„ํ–‰์‹œํ‚จ ๊ฒƒ๊ณผ ๋™์ผํ•˜๋‹ค.

์ฆ‰, ํ•œ ๋ฒˆ ์ง„ํ–‰ํ•  ๋•Œ๋งˆ๋‹ค ์ฒ˜์Œ ์˜ˆ์‹œ๋ฅผ ๋“ค์—ˆ๋–ค ๊ฒƒ ์ฒ˜๋Ÿผ ๊ทธ ๋‹ค์Œ ๋…ธ๋“œ๋กœ ์ด๋™ํ•˜๋Š” ๊ฒƒ๊ณผ ๋น„์Šทํ•œ ๊ฐœ๋…์ธ ๊ฒƒ์ด๋‹ค.

ํฌ์†Œ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜๋ฉด ์ตœ๋Œ€ 50๋งŒ์˜ n,m์—์„œ 19๋ฒˆ๋งŒ ์บ์‹ฑํ•ด๋†“์œผ๋ฉด ๋˜๊ณ ,

20๋งŒ๊ฐœ์˜ ์ฟผ๋ฆฌ๋ฅผ ํ‘ผ๋‹ค๊ณ  ํ•˜์—ฌ๋„ ์ถฉ๋ถ„ํžˆ ์‹œ๊ฐ„์•ˆ์— ์„ธ์ดํ”„ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.




์ด ๊ฐœ๋…์„ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ํ’€ ๋•Œ ๋†“์ณค๋˜ ๋ถ€๋ถ„์€,

ํฌ์†Œ ๋ฐฐ์—ด์„ ๋จผ์ € ๋งŒ๋“ค์–ด ๋†“๊ณ  ๋ฌธ์ œ๋ฅผ ํ’€ ๋•Œ๋Š” ๋งŒ๋“ค์–ด๋†“์€ 1, 2, 4, 8... ํ…Œ์ด๋ธ”์˜ ๊ฐ’์„ ์‚ฌ์šฉํ•˜๊ธฐ๋งŒ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

์ƒ์†Œํ•œ ๊ฐœ๋…์ด์ง€๋งŒ ํ•œ ๋ฒˆ ์ดํ•ดํ•ด๋†“์œผ๋‹ˆ ์•ˆ ๊นŒ๋จน์„ ๊ฒƒ ๊ฐ™๊ธดํ•˜๋‹ค.

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

ํฌ์†Œ ๋ฐฐ์—ด

@tgyuuAn tgyuuAn added tgyuuAn ํ•œ ์ค„๋กœ๋Š” ์†Œ๊ฐœํ•  ์ˆ˜ ์—†๋Š” ๋‚จ์ž. ์ž‘์„ฑ ์ค‘ โฑ๏ธ labels Nov 20, 2024
@tgyuuAn tgyuuAn self-assigned this Nov 20, 2024
@tgyuuAn tgyuuAn marked this pull request as ready for review November 23, 2024 15:08
Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

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

๋น ๋ฅด๊ฒŒ pr์„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž;;

์ฒจ๋ถ€ํ•ด์ฃผ์‹  ๋งํฌ์—์„œ ํฌ์†Œ๋ฐฐ์—ด ... ๊ฐœ๋…์„ ๋ณด๋‹ˆ๊นŒ ๋ถ„๋ช…ํžˆ ๋ณธ ๊ฐœ๋…์ธ๋ฐ ๋ญ์ง€??? ์œ ๋‹ˆ์˜จ-ํŒŒ์ธ๋“œ ํ’€์ด๋ž‘ ํ—ท๊ฐˆ๋ ธ๋‚˜?? ํ•ด์„œ ์ง€๋‚œ ๋ฌธ์ œ๋“ค์„ ์ญ‰ ๋Œ์•„๋ณด๋˜ ์ค‘์— ,,

#207 PR์„ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค. ๊ฐœ๋ฏธ ๋ฌธ์ œ์—์š”!!

์ง€๋‚œ PR์—๋„ 2^n๋ฒˆ์งธ ๋ถ€๋ชจ์ฐพ๊ธฐ๋ผ๊ณ  ์ฝ”๋ฉ˜ํŠธ ์ ์—ˆ์—ˆ๋„ค์š” ๐Ÿ˜… ๊ทธ์น˜๋งŒ,,, ์ €๋Š” ๋ชป ๋– ์˜ฌ๋ ธ๋‹ค์ฃ ,,

ํ˜น์‹œ ๋‹ค๋ฅธ ํฌ์†Œ๋ฐฐ์—ด ๋ฌธ์ œ ์ฐพ๊ณ  ๊ณ„์‹ ๋‹ค๋ฉด ๊ฐœ๋ฏธ retry ์–ด๋– ์‹ ๊ฐ€์š”?!

๋ฌธ์ œํ‘ธ๋Š๋ผ ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!!

@tgyuuAn tgyuuAn merged commit 7b0570c into main Dec 1, 2024
@tgyuuAn tgyuuAn deleted the 82-tgyuuAn branch December 1, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tgyuuAn ํ•œ ์ค„๋กœ๋Š” ์†Œ๊ฐœํ•  ์ˆ˜ ์—†๋Š” ๋‚จ์ž. ๋ฆฌ๋ทฐ ์™„๋ฃŒ โœ”๏ธ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants