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

1-dhlee777 #4

Merged
merged 1 commit into from
Mar 14, 2024
Merged

1-dhlee777 #4

merged 1 commit into from
Mar 14, 2024

Conversation

dhlee777
Copy link
Contributor

@dhlee777 dhlee777 commented Mar 12, 2024

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

https://www.acmicpc.net/problem/1697

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

2์‹œ๊ฐ„40๋ถ„

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

์ˆ˜๋นˆ์ด์˜ ๊ฐ์œ„์น˜์—์„œ +1,-1,*2 ์˜ ํƒ์ƒ‰์„ ์ง„ํ–‰ ํ•  ์ˆ˜ ์žˆ๊ณ  ์ตœ์†Œ์‹œ๊ฐ„์„ ๊ตฌํ•ด์•ผ ํ•˜๊ธฐ๋•Œ๋ฌธ์— bfs๋ฅผ ์ด์šฉํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. (ํ† ๋งˆํ† ์ต๊ธฐ ๋ฌธ์ œ๋ฅผ ๊ทธ์ „์—ํ’€์–ด๋ดค๋Š”๋ฐ ๊ทธ๋ฌธ์ œ ์™€ ๋น„์Šทํ•œ์œ ํ˜•์˜ ๋ฌธ์ œ์ธ๋ฐ ํ† ๋งˆํ† ๋Š” ๋™์„œ๋‚จ๋ถ์œผ๋กœ ํƒ์ƒ‰์„ ์ง„ํ–‰ ํ•  ์ˆ˜ ์žˆ๊ณ  ์‹œ์ž‘์ง€์  ๋„ 2๊ฐœ์˜€์—ˆ์Šต๋‹ˆ๋‹ค)




์ž…๋ ฅ์œผ๋กœ๋Š” ์ˆ˜๋นˆ์ด์˜ ์œ„์น˜, ๋™์ƒ์˜ ์œ„์น˜๊ฐ€ ๊ฐ๊ฐ ์ฃผ์–ด์ง€๊ธฐ๋•Œ๋ฌธ์— ๋ณ€์ˆ˜ start,end์— ๊ฐ๊ฐ ์œ„์น˜๊ฐ’์„ ๋ฐ›์•„์ค€๋’ค ๊ทธ ๋ณ€์ˆ˜๋“ค์„ ์ด์šฉํ•˜์—ฌ bfs๋ฅผ ์ง„ํ–‰ํ•ด์ค๋‹ˆ๋‹ค.




dt๋ฐฐ์—ด์€ ์ˆ˜๋นˆ์ด์˜ ์œ„์น˜์— ๋”ฐ๋ฅธ ์ตœ์†Œ ์‹œ๊ฐ„์„ ๋‚˜ํƒ€๋‚ด ์ฃผ๋Š” ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค.

dt[7]=3์ด๋ผ๋ฉด ์ˆ˜๋นˆ์ด๊ฐ€ ์‹œ์ž‘ ์œ„์น˜์—์„œ 7๊นŒ์ง€ ๊ฐ€๋Š”๋ฐ 3์ดˆ๊ฐ€ ๊ฑธ๋ ธ๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค.

dt๋ฐฐ์—ด์€ ์ฒ˜์Œ ์„ ์–ธ ์‹œ ์ „๋ถ€ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ’์ด 0์ผ์‹œ ๋ฐฉ๋ฌธ ๋˜์ง€ ์•Š์€ ์ ์œผ๋กœ ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ ์ฒ˜์Œ ์‹œ์ž‘ ์œ„์น˜์˜ ๊ฒฝ์šฐ ๊ฐ’์ด (dt[start]=0)(๋ฐฉ๋ฌธ ๋˜์ง€ ์•Š์€ ์ ) ์ด๊ธฐ์— ๋‚˜์ค‘์— ์ด์ƒํ•œ ์‹œ๊ฐ„ ๊ฐ’์ด ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋Š”๋ฐ ์ด๊ฒƒ์€ ๊ฒฐ๊ณผ ๊ฐ’์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค.

bfsํ•จ์ˆ˜์˜ ๊ฒฝ์šฐ ์ผ๋‹จ ์ˆ˜๋นˆ์ด์˜ ์‹œ์ž‘ ์ง€์  ์„ ํ์— ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. ๊ทธ ํ›„ ์ด์ œ ํ๊ฐ€ ๋นŒ ๋•Œ๊นŒ์ง€ ๊ณ„์† while๋ฌธ์„ ์ง„ํ–‰ํ•ด์ค๋‹ˆ๋‹ค.







while๋ฌธ์˜ ๊ฒฝ์šฐ ์ผ๋‹จ ํ์—์„œ ์ œ์ผ ์•ž์— ์žˆ๋Š” ์œ„์น˜๋ฅผ ๊บผ๋‚ธ ๋‹ค์Œ ,

1)๋งŒ์•ฝ ๊ทธ ์œ„์น˜๊ฐ€ ๋™์ƒ์˜ ์œ„์น˜์ผ ๊ฒฝ์šฐ

๋™์ƒ์„ ์ฐพ์€ ๊ฒƒ์ด๋ฏ€๋กœ ๋” ์ด์ƒ์˜ ํƒ์ƒ‰์ด ํ•„์š”ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ dt[end]๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ  ํ•จ์ˆ˜๋ฅผ ์ข…๋ฃŒํ•ด์ค๋‹ˆ๋‹ค.

2) ๊ทธ ์™ธ

์ˆ˜๋นˆ์ด๊ฐ€ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์œ„์น˜๋Š” ์„ธ ๊ฐ€์ง€์ค‘ ์ผ๋‹จ -1,+1 ๋‘ ๊ฐ€์ง€ ๊ฒฝ์šฐ๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ธฐ์—,
๋งŒ์•ฝ ํ์—์„œ ๊บผ๋‚ธ ์œ„์น˜์—์„œ -1,+1์„ ํ•˜์˜€์„ ๊ฒฝ์šฐ ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ์œ„์น˜์ด๊ณ  ๋ฒ”์œ„๋ฅผ
๋งŒ์กฑํ•œ๋‹ค๋ฉด ๊ทธ ์ „ ์œ„์น˜์˜ ์‹œ๊ฐ„+1์„ ํ•ด์ค€ ๊ฐ’์„ ํ˜„์žฌ ์œ„์น˜์˜ ๋ฐฐ์—ด์— ์ €์žฅํ•ด์ค๋‹ˆ๋‹ค.

3)์ถ”๊ฐ€์ ์œผ๋กœ..

*2๋„ ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ ์ด ๊ฒฝ์šฐ์—๋„ 2๋ฒˆ์˜ ๊ฒฝ์šฐ
์™€ ๋™์ผํ•˜๊ฒŒ ์ง„ํ–‰ํ•ด์ค๋‹ˆ๋‹ค.




๋งŒ์•ฝ ํ๊ฐ€ ๋น„์ง€ ์•Š์•˜๋‹ค๋ฉด ์ด ๊ณผ์ •์„ ํ๊ฐ€ ๋น„๊ฑฐ๋‚˜ ๋™์ƒ์„ ์ฐพ์„ ๋•Œ๊นŒ์ง€ ๊ณ„์† ๋ฐ˜๋ณตํ•ด์ค๋‹ˆ๋‹ค.

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

bfs์˜ ๊ฐœ๋…์„ ๋” ํ™•์‹คํ•˜๊ฒŒ ์•Œ ์ˆ˜ ์žˆ์—ˆ๋˜ ๋ฌธ์ œ ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@tgyuuAn
Copy link
Member

tgyuuAn commented Mar 13, 2024

์ œ๊ฐ€ ์กฐ๊ธˆ ๋งˆํฌ๋‹ค์šด ๋ฌธ๋ฒ•์„ ๋„ฃ์–ด๋ดค๋Š”๋ฐ,

๋‹ค์Œ์—๋Š” ์กฐ๊ธˆ ๋” ๊ฐ€๋…์„ฑ ์ข‹๊ฒŒ ์—ฌ๋Ÿฌ ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•ด์„œ ๊พธ๋ฉฐ๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!!

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.

๋ง›์žˆ๋Š” ์ฝ”๋“œ ์ž˜ ์ฝ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค!

#include<iostream>
#include<queue>
using namespace std;
int dt[100001]; // ๏ฟฝรฐ๏ฟฝ(๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ)๏ฟฝ๏ฟฝ ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝฯด๏ฟฝ ๏ฟฝ่ฟญ,๏ฟฝฮต๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝฬฐ๏ฟฝ ๏ฟฝึด๏ฟฝ ๏ฟฝ๏ฟฝฤก๏ฟฝฬด๏ฟฝ.
Copy link
Collaborator

Choose a reason for hiding this comment

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

ํ˜น์‹œ dt๋Š” ์ œ๊ฐ€ ์•Œ๊ณ ์žˆ๋Š” Delta Time์ผ๊นŒ์š”?
์นœ์ˆ™ํ•œ ๋‹จ์–ด๊ตฐ์š”...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

delta time์ด๋ผ๋Š” ์šฉ์–ด๊ฐ€ ์žˆ์—ˆ๊ตฐ์š”.. ๋ฐฉ๊ธˆ ์ฐพ์•„๋ดค๋Š”๋ฐ ๊ฒŒ์ž„์‹œ๊ฐ„์— ๊ด€๋ จ๋œ์šฉ์–ด๋„ค์š” ..! ์ €๋Š” ๊ทธ๋ƒฅ distance๋ฅผ ์ค„์—ฌ์„œ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค ๋‹ค์Œ๋ถ€ํ„ฐ๋Š” time_taken ๋“ฑ ๋” ๋ช…ํ™•ํ•œ ํ‘œํ˜„์„ ์จ์•ผ๊ฒ ๋„ค์š” ์ƒˆ๋กœ์šด ๋‹จ์–ด ์ž˜ ์•Œ์•„๊ฐ‘๋‹ˆ๋‹ค ~!

#include<queue>
using namespace std;
int dt[100001]; // ๏ฟฝรฐ๏ฟฝ(๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ)๏ฟฝ๏ฟฝ ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝฯด๏ฟฝ ๏ฟฝ่ฟญ,๏ฟฝฮต๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝฬฐ๏ฟฝ ๏ฟฝึด๏ฟฝ ๏ฟฝ๏ฟฝฤก๏ฟฝฬด๏ฟฝ.
int k[3] = { -1,1}; //-1,1๏ฟฝ๏ฟฝ ๏ฟฝ๏ฟฝฤก๏ฟฝฬต๏ฟฝ๏ฟฝ๏ฟฝ ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝึฑ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ ๏ฟฝ่ฟญ
Copy link
Collaborator

Choose a reason for hiding this comment

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

-1, +1 ๋งŒ ๋„ฃ์—ˆ๋Š”๋ฐ ํ˜น์‹œ ์™œ 3์œผ๋กœ ๋ฐฐ์—ด์นธ์„ ์žก์œผ์…จ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

์ฒ˜์Œ์— *2๋ฅผ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ• ์ง€ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ 3์นธ์„ ์žก์•„๋†จ์—ˆ๋Š”๋ฐ ๊ฒฐ๊ตญ ๋‚˜์ค‘์— if๋ฌธ์œผ๋กœ ๋”ฐ๋กœ ์ฒ˜๋ฆฌํ•ด์คฌ์Šต๋‹ˆ๋‹ค ํฌ๊ธฐ๋ฅผ 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.

๋ง›์žˆ๋Š” ์ฝ”๋“œ ์ž˜ ์ฝ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค!

@dhlee777
Copy link
Contributor Author

์ œ๊ฐ€ ์กฐ๊ธˆ ๋งˆํฌ๋‹ค์šด ๋ฌธ๋ฒ•์„ ๋„ฃ์–ด๋ดค๋Š”๋ฐ,

๋‹ค์Œ์—๋Š” ์กฐ๊ธˆ ๋” ๊ฐ€๋…์„ฑ ์ข‹๊ฒŒ ์—ฌ๋Ÿฌ ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•ด์„œ ๊พธ๋ฉฐ๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!!

์ •๋ง ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค !! ๋งˆํฌ๋‹ค์šด์— ๋” ์ต์ˆ™ํ•ด์ ธ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค ..

Copy link
Collaborator

@yuyu0830 yuyu0830 left a comment

Choose a reason for hiding this comment

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

์ฝ”๋“œ ๊น”๋”ํ•˜๋„ค์š” :)
์ˆจ๋ฐ”๊ผญ์งˆ ์‹œ๋ฆฌ์ฆˆ๊ฐ€ ์œ ํ–‰์ธ๊ฐ€์š”

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.

์ˆจ๋ฐ”๊ผญ์งˆ ์‹œ๋ฆฌ์ฆˆ ๋กœ ์ œ bfs ๋Šฅ๋ ฅ์ด ํ–ฅ์ƒ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ข‹์€ ๋ฌธ์ œ ์ž˜ ๋ณด๊ณ  ๊ฐ‘๋‹ˆ๋‹ค.

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