์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

image

 

image

๋ฐ˜์‘ํ˜•

์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์—ด์–ด ํžˆ์Šคํ† ๊ทธ๋žจ์„ ์ƒ์„ฑํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ž„.

๋ฐ˜์‘ํ˜•

์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

1. ์—ฌ๋Ÿฌ๋ถ„์ด ์–‘๊ถ์„ ์ˆ˜๋ผ๊ณ  ํ•ด๋ณด์ž. 30.0 m ์ „๋ฐฉ์— ์žˆ๋Š” ๊ณผ๋…์— ํ™œ์‹œ์œ„๋ฅผ ์ตœ๋Œ€๋กœ ๋‹น๊ฒจ, ์ฒ˜์Œ์— ์ˆ˜ํ‰ ๋ฐฉํ–ฅ์œผ๋กœ ์˜์•˜๋”๋‹ˆ ์ž์‹ 

์˜ ํ™œ ์ค‘์•™๊ณผ ๋˜‘ ๊ฐ™์€ ๋†’์ด์— ์žˆ๋Š” ๊ณผ๋… ์ค‘์•™์œผ๋กœ๋ถ€ํ„ฐ ์—ฐ์ง ํ•˜๋ฐฉ์œผ๋กœ 1.25 m ๋–จ์–ด์ง„ ๋†’์ด์— ํ™”์‚ด์ด ๊ฝ‚ํžŒ ๊ฒƒ์„ ๋ง์›๊ฒฝ์œผ๋กœ ํ™•

์ธํ–ˆ๋‹ค๊ณ  ํ•˜์ž. ๋‘ ๋ฒˆ์งธ ์‹œ์œ„์—์„œ ์ฒ˜์Œ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํ™œ์‹œ์œ„๋ฅผ ์ตœ๋Œ€๋กœ ๋‹น๊ฒจ ๊ณผ๋… ์ค‘์•™์— ๋ช…์ค‘์‹œํ‚ค๋ ค๋ฉด ๋ช‡ ๋„ ์ƒ๋ฐฉ์œผ๋กœ ์˜์•„

์•ผ ํ• ๊นŒ? (์ค‘๋ ฅ๊ฐ€์†๋„๋Š” g=9.80 m/s^2 ๋กœ ๋†“์„ ๊ฒƒ.)


x์„ฑ๋ถ„๊ณผ y์„ฑ๋ถ„์€ ๋ณ„๊ฐœ๋‹ค.

y์„ฑ๋ถ„์„ ํ†ตํ•ด ์‹œ๊ฐ„์„ ๊ตฌํ• ์ˆ˜ ์žˆ๋‹ค.

๊ณผ๋…์—์„œ 1.25m ๋ฐ‘์œผ๋กœ ๊ฐ”์œผ๋ฏ€๋กœ...

๊ถค์  = Vy0 * t + 1/2*a*t^2 ์—์„œ
์ฃผ์–ด์ง„ ๋Œ€๋กœ Vy0 = 0์ด๊ณ  a = 9.8m/s^2์ด๋ฏ€๋กœ t๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

1.25 = 0*t + 1/2*9.8 * t^2
1.25 * 2 / 9.8 = t ^ 2
t = ๋ฃจํŠธ(2.5/9.8)
t = 5/๋ฃจํŠธ(98)์ดˆ


x์„ฑ๋ถ„์„ ์ƒ๊ฐํ•ด๋ณด๋ฉด ์‹œ๊ฐ„์„ ์œ„ํ•ด์„œ ๊ตฌํ–ˆ์œผ๋ฏ€๋กœ ๊ทธ๊ฑธ ํ† ๋Œ€๋กœ ์ฒ˜์Œ ์†๋„๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.
30 = V0 * 5/๋ฃจํŠธ(98) + 1/2*0*t^2
Vx0 = 6*๋ฃจํŠธ(98)m/s^2


์ด์ œ ์œ„ ๋‘ ์‹์„ ํ† ๋Œ€๋กœ y์„ฑ๋ถ„์— ์–ผ๋งˆ๋งŒํผ์˜ ์†๋„๊ฐ€ ๊ฐ€์•ผ ๊ณผ๋…˜์ •์ค‘์•™์— ๋งž์„๊นŒ๋ฅผ ์ƒ๊ฐํ•ด๋ณด๋ฉด

๊ถค์  = V0*t + 1/2*a*t^2์—์„œ ์ •์ค‘์•™์— ๋งž๋Š”๋‹ค๋Š” ๋ง์€ ์˜ฌ๋ผ๊ฐ”๋‹ค๊ฐ€ ๋‹ค์‹œ ๋‚ด๋ ค๊ฐ€์„œ ๊ฒฐ๊ณผ์ ์œผ๋กœ ๊ถค์ ์ด 0์ด๋ผ๋Š” ๋œป์ด๋‹ค.

์ฆ‰, 0 = Vy0 * t - 1/2*9.8*t^2์—์„œ t= 5/๋ฃจํŠธ(98)์ดˆ

0 = Vy0 * 5/๋ฃจํŠธ(98) - 1/2*9.8*(5/๋ฃจํŠธ(98))^2

Vy0*5/๋ฃจํŠธ(98) = 4.9*25/98
Vy0 = 4.9*25/98/5*๋ฃจํŠธ(98)
Vy0 = ๋ฃจํŠธ(98)/4


Sin์Ž„ํƒ€ = 6*๋ฃจํŠธ(98)   /   ๋ฃจํŠธ(98)/4
        = 1/24

์Ž„ํƒ€ = ArcSIN(1/24) =  0.0416787324225779
๊ฐ’์ด ๋ผ๋””์•ˆ ์ด๋ฏ€๋กœ 360๋„๊ฐ๋„๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด

2.388015...
์Ž„ํƒ€ = ์•ฝ 2.4๋„






2. ์ปค๋‹ค๋ž€ ๋„๋ฅด๋ž˜์— ํŠผํŠผํ•œ ์ค„์ด ํ•˜๋‚˜ ๊ฑธ์ณ์ ธ ์žˆ๊ณ  ์–‘์ชฝ์— ๋ฌด๊ฒŒ๋ฅผ ๋ฌด์‹œํ•  ์ˆ˜ ์žˆ๋Š” ์ €์šธ ๋‘ ๊ฐœ๊ฐ€ ๋‹ฌ๋ ค ์žˆ๋‹ค๊ณ  ํ•˜์ž. ๊ฐ ์ €์šธ

์— ๋ชธ๋ฌด๊ฒŒ๊ฐ€ 70 ํ‚ฌ๋กœ๊ทธ๋žจ๊ณผ 50 ํ‚ฌ๋กœ๊ทธ๋žจ์ธ ๋‘ ์‚ฌ๋žŒ์ด ๊ฐ๊ฐ ์˜ฌ๋ผ ํƒ„๋‹ค๊ณ  ํ•˜๋ฉด ๋‹น์—ฐํžˆ ๋ชธ๋ฌด๊ฒŒ๊ฐ€ ๋” ๋ฌด๊ฑฐ์šด ์‚ฌ๋žŒ ์ชฝ์ด ๋‚ด๋ ค์˜ค๊ฒŒ

๋  ๊ฒƒ์ด๋‹ค. ์ด ๋•Œ ์ €์šธ์— ๋‚˜ํƒ€๋‚œ ๊ฐ ์‚ฌ๋žŒ์˜ ๋ชธ๋ฌด๊ฒŒ๋ฅผ ๊ตฌํ•ด ๋ณด์‹œ์˜ค.

"๋ชธ๋ฌด๊ฒŒ"๋Š” ํž˜์˜ ์ฐจ์›์ด๋‹ค.(ํ‚ฌ๋กœ๊ทธ๋žจ์ค‘ ์œผ๋กœ ํ‘œ๊ธฐ๋˜์–ด์žˆ์ง€ ์•Š์•„ ์™œ ์ค‘๋ ฅ๊ฐ€์†๋„๊ฐ€ ์•ˆ ์ฃผ์–ด ์กŒ๋Š”์ง€ ํ—ท๊ฐˆ๋ ธ์Šต๋‹ˆ๋‹ค.)
ํ•ฉ๋ ฅ์„ ๊ตฌํ•˜๋ฉด ๋ฌด๊ฑฐ์šด์ชฝ์œผ๋กœ ํž˜์ด ์ ๋ฆฌ๊ฒŒ ๋œ๋‹ค.
์ฆ‰ ์ €์šธ์— 70ํ‚ฌ๋กœ๊ทธ๋žจ์œผ๋กœ ๋‚˜์™”๋˜ ์ชฝ์œผ๋กœ 50ํ‚ฌ๋กœ๊ทธ๋žจ์„ ๋บ€ 20ํ‚ฌ๋กœ๊ทธ๋žจ์˜ ๋ฌด๊ฒŒ๋งŒํผ ์ž‘์šฉํ•˜๊ฒŒ ๋œ๋‹ค.

๊ทธ๋ž˜์„œ ๋ชธ๋ฌด๊ฒŒ๊ฐ€ 70ํ‚ฌ๋กœ๊ทธ๋žจ์ธ ์‚ฌ๋žŒ์ด ์˜ฌ๋ผํƒ„ ์ชฝ์€ ์ €์šธ์ด 20ํ‚ฌ๋กœ๊ทธ๋žจ์„ ๊ฐ€๋ฆฌํ‚ฌ ๊ฒƒ์ด๊ณ 
50ํ‚ฌ๋กœ๊ทธ๋žจ์ธ ์‚ฌ๋žŒ์ด ํƒ„ ์ชฝ์€ ์ €์šธ์ด 0ํ‚ฌ๋กœ๊ทธ๋žจ์„ ๊ฐ€๋ฆฌํ‚ฌ ๊ฒƒ์ด๋‹ค.


3. ์ˆ˜์—… ์‹œ๊ฐ„์— ์งˆ๋Ÿ‰์ด m1, m2 ์ธ ๋‘ ๋ฌผ์ฒด๋ฅผ ์ˆ˜ํ‰ํ•œ ๋ฐ”๋‹ฅ ์œ„์— ๋†“๊ณ  ์„œ๋กœ ์ ‘์ด‰์‹œ์ผœ ๋†“์€ ๋’ค ์ˆ˜ํ‰ ๋ฐฉํ–ฅ์˜ ํž˜ F ๋ฅผ m1 ์— ๊ฐ€ํ•œ

๊ฒฝ์šฐ ์–ด๋–ป๊ฒŒ ์›€์ง์ด๋ฉฐ, ์ฃผ๊ณ  ๋ฐ›๋Š” ํž˜์€ ์–ผ๋งˆ๋‚˜ ๋˜๋Š”์ง€ ๊ณ„์‚ฐํ•ด ๋ณด์•˜๋‹ค. ์—ฌ๊ธฐ์— ์งˆ๋Ÿ‰ m3 ์ธ ๋ฌผ์ฒด๋ฅผ ํ•˜๋‚˜ ๋” m2 ์˜†์— ๋ถ™์—ฌ ๋†“์„

๊ฒฝ์šฐ ๊ฐ€์†๋„์™€ ์ฃผ๊ณ  ๋ฐ›๋Š” ํž˜๋“ค์„ ๊ตฌํ•ด ๋ณด์‹œ์˜ค. ๋˜, m1 ๋ถ€ํ„ฐ mN ๊นŒ์ง€์˜ ๋ฌผ์ฒด๊ฐ€ ๋ถ™์–ด ์žˆ๋Š” ๊ฒฝ์šฐ๋กœ ์ผ๋ฐ˜ํ™”ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์ƒ๊ฐํ•ด

๋ณด์‹œ์˜ค.

m3๊นŒ์ง€ ์žˆ๋Š”๊ฒฝ์šฐ๋Š”

F   =   (m1 + m2 + m3) * a
์ฆ‰ ๊ฐ€์†๋„๋Š”
a =  F / (m1 + m2 + m3)

์งˆ๋Ÿ‰์ด m1์ธ ๋ฌผ์ฒด๊ฐ€ ๋ฐ›๋Š” ์•Œ์งœํž˜ F   + F12  = m1*a
์งˆ๋Ÿ‰์ด m2์ธ ๋ฌผ์ฒด๊ฐ€ ๋ฐ›๋Š” ์•Œ์งœํž˜ F21 + F23  = m2*a
์งˆ๋Ÿ‰์ด m3์ธ ๋ฌผ์ฒด๊ฐ€ ๋ฐ›๋Š” ์•Œ์งœํž˜ F32        = m3*a


mN๊นŒ์ง€์˜ ๋ฌผ์ฒด๊ฐ€ ๋ถ™์–ด์žˆ๋Š” ์ผ๋ฐ˜์ ์ธ ๊ฒฝ์šฐ๋Š”

๊ฐ€์†๋„ a = F / (m1 + m2 + m3 + ... + mN)
         = F / (โˆ‘K๋Š”1์—์„œn๊นŒ์ง€) mK

๋ฌผ์ฒด๊ฐ€ N๊ฐœ์ผ๋•Œ ๊ฐ ๋ฌผ์ฒด๊ฐ€ ์ฃผ๊ณ  ๋ฐ›๋Š” ํž˜์€
์งˆ๋Ÿ‰์ด mK์ธ ๋ฌผ์ฒด๊ฐ€ ๋ฐ›๋Š” ์•Œ์งœํž˜ FK(K-1) + FK(K+1) = mK*a (K๊ฐ€ 1๊ณผ N์ด ์•„๋‹๋•Œ)

K๊ฐ€ 1์ผ๋•, F + FK(K+1) = mK*a
K๊ฐ€ N์ผ๋•, FN(N-1) = mN*a

๋ฐ˜์‘ํ˜•

์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

์ถœ์ฒ˜ : http://www.hyunlog.com/blog/entry/์™œ-์•Œ๊ณ ๋ฆฌ์ฆ˜์„-์•Œ์•„์•ผ-ํ•˜์ง€

 

 

์™œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์•Œ์•„์•ผ ํ•˜์ง€?

์•Œ๊ณ ๋ฆฌ์ฆ˜์— ๋Œ€ํ•ด ๊ธ€์„ ์จ ๋ณด๊ธฐ๋กœ ํ–ˆ๋‹ค.
๋‚˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ „์‚ฐํ•™์˜ ๊ฐ€์žฅ ๊ธฐ๋ณธ, ๊ฐ์ดˆ๋ผ ์ƒ๊ฐํ•œ๋‹ค.  ์ธ๊ณต์ง€๋Šฅ, ์šด์˜์ฒด์ œ, DBMS ๋“ฑ ์ „์‚ฐํ•™์˜ ์–ด๋””์—๊ณ  ์ ์ ˆํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ๋Œ€ํ•œ ์ดํ•ด๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š๋Š” ๊ณณ์ด ์—†๋‹ค.  ํŠœ๋ง์ƒ์„ ๋ฐ›์€ ์‚ฌ๋žŒ๋“ค์„ ๋ณด๋”๋ผ๋„ ๊ทธ ์ค‘ ๋งŽ์€ ์‚ฌ๋žŒ๋“ค์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋ฐฐ์šฐ๋‹ค ๋ณด๋ฉด ๋‚˜์˜ค๋Š” ์–‘๋ฐ˜๋“ค์ด๋‹ค.
๋‚˜๋Š” ๋Œ€ํ•™์›์—์„œ ์ˆ˜ํ•™์  ๋…ผ๋ฆฌํ•™๊ณผ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋ฐฐ์šฐ๋ฉด์„œ ๋‚ด๊ฐ€ ์ด ์ชฝ์—์„œ ์—‘์ŠคํผํŠธ๊ฐ€ ๋  ๋งŒํผ ์Šค๋งˆํŠธํ•˜์ง€ ์•Š๋‹ค๋Š” ๊ฒƒ์„ ์•Œ์•˜๋‹ค.  ๊ทธ๋ž˜๋„ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ์ „์‚ฐํ•™์„ ํ•˜๊ธฐ์— ํ•„์š”ํ•˜๋ฏ€๋กœ ์•Œ๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ด ๋…ธ๋ ฅํ–ˆ๋‹ค.  ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฑ…์„ ๋งˆ์ง€๋ง‰ ๋ณธ๊ฒฉ์ ์œผ๋กœ ๋ณธ ๊ฒƒ์ด 92๋…„ ๊ฒฝ์ด๋ผ ๊ธฐ์–ตํ•œ๋‹ค.  
์™œ ์ง€๊ธˆ ๋‹ค์‹œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ƒ๊ฐ๋‚ ๊นŒ?
์šฐ๋ฆฌ ํšŒ์‚ฌ์—์„œ ์ƒˆ๋กœ์šด ์ƒํ’ˆ์„ ์ค€๋น„ํ•˜๋Š”๋ฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ›ˆ๋ จ์ด ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.  ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ›ˆ๋ จ์ด ๋˜์ง€ ์•Š์€ ์‚ฌ๋žŒ์€ ๋‹จ์ˆœ coder ์ด๊ณ , ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ดํ•ดํ•˜๊ณ  ์ ์šฉํ•˜๋ฉด์„œ ๋ถ€ํ„ฐ ํ”„๋กœ๊ทธ๋ž˜๋จธ๋ผ ๋ถ€๋ฅผ ์ˆ˜ ์žˆ๋‹ค.  ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ›ˆ๋ จ์ด ๋˜๊ณ  ์ด์— ๋ฐ”ํƒ•ํ•œ ์ „์‚ฐํ•™์˜ ์—ฌ๋Ÿฌ ๋ถ„์•ผ๋ฅผ ์•Œ๊ฒŒ๋˜๋ฉด ์ปดํ“จํ„ฐ ์—”์ง€๋‹ˆ์–ด ๋˜๋Š” ๊ณผํ•™์ž๋ผ ๋ถ€๋ฅธ๋‹ค.  ์ปดํ“จํ„ฐ ์—”์ง€๋‹ˆ์–ด/๊ณผํ•™์ž์˜ ์˜์›ํ•œ ์‚ฌ๋ถ€์ธ Donald Knuth์˜ The Art of Computer Programming ์„ ๋ณด์ž.  ์ฑ…์ด๋ฆ„์„ "์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ์ˆ " ์ด๋ผ๊ณ  ํ–ˆ๋‹ค.  ์ด ๊ฒƒ ๋ณด๊ณ  ์ดํ•ดํ•ด์•ผ์ง€ ํ”„๋กœ๊ทธ๋ž˜๋จธ๋ž€๋‹ค.  ์šฐ๋ฆฌ ํšŒ์‚ฌ๊ฐ€ ์ข‹์€ ํ”„๋กœ๊ทธ๋ž˜๋จธ, ์—”์ง€๋‹ˆ์–ด๊ฐ€ ํ•„์š”ํ•˜๊ณ  ๋‚˜๋ถ€ํ„ฐ ๋‹ค์‹œ ํ›ˆ๋ จํ•ด์•ผ ์ง์›๋“ค ๋„์™€ ์ค„ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋‹ค.
์•Œ๊ณ ๋ฆฌ์ฆ˜์„ Cormen ๋“ฑ์ด ์“ด Introduction to Algorithms ์œผ๋กœ ๊ณต๋ถ€ํ–ˆ๋‹ค.  ๊ฝค ๋‘๊บผ์šด ์ฑ…์œผ๋กœ ์ด ์ชฝ ๋ถ„์•ผ์— ๋ฒ ์ŠคํŠธ์…€๋Ÿฌ๋‹ค.  ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์‰ฝ์ง€ ์•Š๋‹ค.  ์˜ค์ฃฝํ•˜๋ฉด ๋นŒ ๊ฒŒ์ด์ธ ๊ฐ€ "๋„ˆ๊ฐ€ ์ •๋ง ์ข‹์€ ํ”„๋กœ๊ทธ๋ž˜๋จธ๋ผ๋ฉด Knuth์˜ The Art of Programming์„ ๋ณด์•„์•ผ ํ•˜๊ณ , ์ •๋ง ๋‹ค ์ฝ์—ˆ์œผ๋ฉด ์žฌ๋นจ๋ฆฌ ์ž๊ธฐ์—๊ฒŒ ์ด๋ ฅ์„œ ๋ณด๋‚ด๋ผ" ํ–ˆ์„๊นŒ?  ์ด ์ฑ… ์ด 4๊ถŒ์ด๋‹ค.  ์•„๋งˆ ์ด ๋ถ„์•ผ์—์„œ ๊ฐ€์žฅ ์œ ๋ช…ํ•˜๋ฉด์„œ๋„ ๊ฐ€์žฅ ๋งŽ์ด ์ณ๋‹ค ๋ณด๊ธฐ๋งŒ ํ•œ ์ฑ…์ผ ๊ฒƒ์ด๋‹ค.  ์ด ์ฑ…๋“ค 4๊ถŒ ๋‹ค ์ฝ์€ ์‚ฌ๋žŒ์ด๋ผ๋ฉด ๋ˆ„๊ฐ€ ์ฑ„๊ฐ€๋Š”์ง€๋„ ๋ชจ๋ฅด๊ฒŒ ์ฑ„ ๊ฐˆ ๊ฒƒ์ด๋‹ค.  ๊ตฌ๊ธ€์˜ ์„ธ๋ฅด๊ฒŒ์ด ๋ธŒ๋ฆฐ์ด ์•„๋งˆ๋„ ์ „์šฉ ๋น„ํ–‰๊ธฐ ๋ณด๋‚ผ ์ง€๋„ ๋ชจ๋ฅธ๋‹ค.
์ด ์ •๋„๋ฉด ์ธ์„ผํ‹ฐ๋ธŒ ๋˜์ง€ ์•Š์„๊นŒ?
90๋…„๋Œ€ ์ดˆ์™€ ์ง€๊ธˆ ๊ฝค ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ง€ํ˜•์ด ๋ฐ”๋€Œ์—ˆ๋‹ค.  ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ๋ฐ”๋€ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜๋Š” SW ํ™˜๊ฒฝ์ด ๋ฐ”๋€Œ์—ˆ๋‹ค.  ๊ฐ€์žฅ ํฐ ๋ณ€ํ™”๋Š” JAVA์™€ ๊ฐ™์€ ๊ฐ์ฒด์ง€ํ–ฅ ์–ธ์–ด์™€ ๊ธฐ์ˆ ์ด ๋ณด๊ธ‰๋˜๋ฉด์„œ JAVA์˜ Collection ๊ฐ™์ด ํŽธ๋ฆฌํ•œ ์ž๋ฃŒ๊ตฌ์กฐ API ๋“ค์ด ๋“ฑ์žฅํ•œ ๊ฒƒ์ด๋‹ค.  ์•„์ฃผ ์ข‹์€ ํ˜„์ƒ์ด๋‹ค. 
JAVA Collection ๊ฐ™์€ ๋„๊ตฌ, ํ•™๋ถ€์—์„œ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ๊ฐ€๋ฅด์น˜๋ฉด์„œ ๋Š๊ผˆ๋˜ ์–ด๋ ค์›€, ๊ทธ๋ฆฌ๊ณ  ์ตœ๊ทผ์— ๋Œ€ํ•™์›์—์„œ ๊ฐ์ฒด์ง€ํ–ฅ ๊ธฐ์ˆ ์„ ๊ฐ•์˜ํ•˜๋ฉด์„œ ์ƒ๊ธด ์†Œํ”„ํŠธ์›จ์–ด ๊ด€์ ์˜ ๋ณ€ํ™”, SW์˜ ์žฌ์‚ฌ์šฉ์„ฑ, ํ˜„์‹ค์ ์œผ๋กœ ์–ด์ฉ” ์ˆ˜ ์—†์ด ๊ณ„์† ์š”๊ตฌ์‚ฌํ•ญ์ด ๋ฐ”๋€Œ๊ธฐ ๋•Œ๋ฌธ์— SW๋Š” ์ง€์†์ ์œผ๋กœ ๋ฐ”๋€”์ˆ˜ ๋ฐ–์— ์—†๋‹ค๋Š” extreme programming ๋ฐฉ๋ฒ•๋ก  ๋“ฑ์ด ๋‹ค ์šฐ๋ฆฌ๊ฐ€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋ณด๋Š” ๋ฐฉ๋ฒ•์˜ ๋ณ€ํ™”๋ฅผ ์š”๊ตฌํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค.  ์˜ˆ์ „์— ์šฐ๋ฆฌ๊ฐ€ red-black tree๋ฅผ ์ง์ ‘ ์งฐ๋‹ค๋ฉด ์ด์ œ๋Š” JAVA Collection ์ค‘์— ์ ๋‹นํ•œ ๋…€์„์„ ๋ถˆ๋Ÿฌ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋œ ๊ฒƒ์ด๋‹ค.  ํŽธ๋ฆฌํ•จ์„ ์–ป์—ˆ์ง€๋งŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์Œ๋ฏธํ•˜๋Š” ๊ธฐ์ˆ ์„ ์žƒ์–ด ๊ฐ„๋‹ค.  ์–ผ๋งˆ๋‚˜ ์ž˜ Collection API๊ฐ€ ๊ตฌํ˜„๋˜์—ˆ์„๊นŒ ๊ถ๊ธˆํ•˜๊ธฐ๋„ ํ•˜๋‹ค.  20๋…„ ์ „์—๋Š” ๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ๋งŒ๋“  ๊ฒƒ ๋ฏฟ์ง€ ๋ชปํ•˜๋‹ˆ ์ง์ ‘ ์ž์‹ ์ด ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ํ–ˆ๊ฒ ์ง€๋งŒ, ์ด์ œ๋Š” ๊ฐ–๋‹ค ์“ฐ๋Š” ๊ฒƒ์ด ๋งž๋‹ค.  ๋‚ด๊ฐ€ ์žฌ์‚ฌ์šฉํ•˜๋„๋ก ๊ฐ€๋ฅด์น˜๋Š”๋ฐ... 
์ด๋Ÿฐ ๊ด€์ ์—์„œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋ณด๊ณ  ์‹ถ๋‹ค.  ๊ฐ์ฒด์ง€ํ–ฅ์˜ ํด๋ž˜์Šค, encapsulation, hierarchy, polymorphism์ด ์ •๋ง ์–ผ๋งˆ๋‚˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์˜์กดํ•˜๋Š” ๋ฐ์ดํ„ฐ๊ตฌ์กฐ (Abstract Data Type)์— ๋”ฑ ๋งž๋Š” ์ง€ (์ •๋ง ๊ทธ๋ ‡๋‹ค), ํฌ์ธํ„ฐ ์—†๋Š” JAVA๋กœ ์–ด๋–ป๊ฒŒ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ž˜ ๊ตฌํ˜„๋˜๋Š”์ง€ ์•Œ์•„ ๋ณด๋ ค ํ•œ๋‹ค.  ํ•˜๋‹ค ๋ณด๋ฉด ๊พ€๊ฐ€ ๋งŽ์ด ๋‚  ํ„ฐ์ธ๋ฐ.  ์žฌ๋Šฅ์ด ๋ถ€์กฑํ•˜๋‹ˆ ์‹œ๊ฐ„๋„ ๊ฑธ๋ฆฌ๊ฒ ๊ณ ,  ๊ทธ๋ ‡์ง€๋งŒ ๋˜ ํ•œํŽธ ๋‚ด๊ฐ€ ์ดํ•ด ํ•  ์ •๋„๋ฉด ์ตœ์†Œํ•œ The Art of Programming ์„ ๊ทธ๋ƒฅ ๋ณด๋Š” ๊ฒƒ ๋ณด๋‹ค๋Š” ๋‚ซ์ง€ ์•Š์„๊นŒ?
์˜ค๋žœ๋งŒ์— ๋จธ๋ฆฌ๋„ ์จ ๋ณด๊ณ , ์ž๋ฐ”๋„ ํ›ˆ๋ จํ•  ๊ฒƒ ๊ฐ™์•„ ์„ค๋ Œ๋‹ค.   
Knuth๊ต์ˆ˜๋‹˜์˜ ๊ฐ•์˜๋ฅผ ๋ณด๊ณ  ์‹ถ์œผ๋ฉด ์—ฌ๊ธฐ๋กœ.   ์žฌ๋ฏธ์žˆ๋Š” ๊ฒƒ์ด ์—ฌ๊ธฐ์— ๋งŽ์Šต๋‹ˆ๋‹ค.   ์˜์–ด์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์•Œ๊ฒŒ๋˜๋ฉด ์ƒˆ๋กœ์šด ์„ธ์ƒ์ด ๋ณด์ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. 
Hang on.

๋ฐ˜์‘ํ˜•

์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

 

์ถœ์ฒ˜ : http://www.buggymind.com/83

 

์š”์ฆ˜ C++๋กœ Admission Control System์„ ๊ฐœ๋ฐœ์ค‘์ž…๋‹ˆ๋‹ค. ๊ทผ๋ฐ ํ”„๋กœ๊ทธ๋žจ์„ ์งœ๋‹ค ๋ณด๋ฉด ์œผ๋ก€ ๊ทธ๋ ‡๊ฒ ์ง€๋งŒ ์ŠคํŠธ๋ง์„ ์ˆซ์ž๋กœ, ์ˆซ์ž๋Š” ์ŠคํŠธ๋ง์œผ๋กœ ๋ณ€ํ™˜ํ•  ์ผ์ด ๋งŽ์ด ์ƒ๊ธฐ๋”๊ตฐ์š”. ์ข…์ „์—๋Š” atoll๊ฐ™์€ ํ•จ์ˆ˜๋ฅผ ์จ์„œ ๊ทธ๋Ÿฐ ๋ณ€ํ™˜์ž‘์—…์„ ํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ, ์›ฌ์ง€ ์˜ค๋Š˜์€ stringstream ํด๋ž˜์Šค๋ฅผ ์จ์„œ ๊ทธ๊ฑธ ํ•ด๋ณด๊ณ  ์‹ถ๋”๊ตฐ์š”. ์–ด์ฉŒ๋‹ค๊ฐ€ Bjarne ์„ ์ƒ๋‹˜์˜ ์ด ๊ธ€์„ ๋ณด๊ฒŒ ๋˜์—ˆ๊ฑฐ๋“ ์š”. "How do I convert an Integer to a String"์ด๋ผ๋Š” ๊ฒƒ์ด ์ œ๋ชฉ์ธ๋ฐ์š”. stringstream ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•ด itos๋ผ๋Š” ํ•จ์ˆ˜(integer๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พธ๋Š”)๋ฅผ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋ž˜์„œ ์ด๋ฒˆ์—๋Š” ๋ฌธ์ž์—ด์„ ์ˆซ์ž๋กœ ๋ฐ”๊พธ๋Š” ์ž‘์—…์„ stringstream์„ ์จ์„œ ํ•ด๋ณด๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฑฐ์˜ ๋น„์Šทํ•˜๊ฒŒ ํ•˜๋ฉด ๋ ๊ฒƒ ๊ฐ™๋”๊ตฐ์š”.

#include <iostream>
#include <sstream>
using namespace std;
long long stoll(const string& v) {
    stringstream ss;
    ss << v;
    long long ret;
    ss >> ret;
    return ret;
}
int main() {
    long long r;
    for ( int i = 0; i < 10000000; ++i ) {
        r = stoll("48623948209834029");
    }
}

๋„ค. ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ•œ ์ฝ”๋“œ๋Š” ์•„์ฃผ ๊ทธ๋Ÿด์‹ธํ•˜๊ฒŒ ์ž˜ ๋Œ์•„๊ฐ‘๋‹ˆ๋‹ค. ๋‚˜๋ฆ„๋Œ€๋กœ 'C++'์ ์ด๊ธฐ๋„ ํ•˜์ง€์š”. ํ•˜์ง€๋งŒ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์ด์œ ๋กœ ์ €๋Š” ์œ„์˜ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ๋ฅผ ํฌ๊ธฐํ–ˆ์Šต๋‹ˆ๋‹ค. ์™œ ๊ทธ๋žฌ๋ƒ๊ณ ์š”? ์œ„์˜ ์ฝ”๋“œ๋ฅผ Unix time ๋ช…๋ น๊ณผ ํ•จ๊ป˜ ์‹คํ–‰ํ•ด๋ณด๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค.
[bjlee@bjlee-xnote test]$ time ./a.out
real    0m24.972s
user    0m23.349s
sys     0m0.060s
[bjlee@bjlee-xnote test]$

ํ•˜์ง€๋งŒ ๊ฐ™์€ ํ”„๋กœ๊ทธ๋žจ์„ stdlib.h์— ์„ ์–ธ๋˜์–ด ์žˆ๋Š” atoll์„ ์จ์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•˜๋ฉด ์–ด๋–จ๊นŒ์š”?
int main() {
    long long r;
    for ( int i = 0; i < 10000000; ++i ) {
        r = atoll("48623948209834029");
    }
}

๊ทธ๋žฌ์„ ๊ฒฝ์šฐ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค.
[bjlee@bjlee-xnote test]$ time ./a.out
real    0m2.306s
user    0m2.276s
sys     0m0.008s
[bjlee@bjlee-xnote test]$

๊ฐ„๋‹จํ•œ ์‹คํ—˜์œผ๋กœ๋„ ์„ฑ๋Šฅ ์ฐจ์ด๊ฐ€ ๊ฝค ํฌ๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ์ฒด ์ƒ์„ฑ๊ณผ ๊ฐ™์€ ๊ธฐํƒ€๋“ฑ๋“ฑ์˜ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ๋ผ์–ด๋“ค๊ธฐ ๋•Œ๋ฌธ์— stringstream์ชฝ์˜ ํผํฌ๋จผ์Šค๊ฐ€ ๋” ์•ˆ์ข‹๊ฒŒ ๋‚˜์˜จ ๊ฒƒ์ด๊ฒ ์ฃ . ๊ทธ๋Ÿผ Bjarne ์•„์ €์”จ๋Š” int๋ฅผ string์ชฝ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์™œ stringstream์„ ์ถ”์ฒœํ•œ ๊ฒƒ์ผ๊นŒ์š”? ๊ทธ๊ฒŒ ๊ถ๊ธˆํ•ด์„œ ๋ฐ˜๋Œ€์ชฝ๋„ ์‹คํ—˜์„ ํ•ด๋ดค์Šต๋‹ˆ๋‹ค.
#include <iostream>
#include <sstream>
using namespace std;
string itos(const long long& v) {
    stringstream ss;
    ss << v;
    string ret;
    ss >> ret;
    return ret;
}
int main() {
    string p;
    for ( int i = 0; i < 10000000; ++i ) {
        p = itos(324879829);
    }
}

์œ„์˜ ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ time์œผ๋กœ ์‹œ๊ฐ„์„ ์žฌ ๋ณด๋ฉด ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
[bjlee@bjlee-xnote test]$ time ./a.out
real    0m19.790s
user    0m19.677s
sys     0m0.012s
[bjlee@bjlee-xnote test]$

๊ทธ๋Ÿผ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?
#include <iostream>
#include <sstream>
using namespace std;
string itos(const long long& v) {
    char buffer[256];
    sprintf(buffer, "%lld", v);
    return string( buffer );
}
int main() {
    string p;
    for ( int i = 0; i < 10000000; ++i ) {
        p = itos(324879829);
    }
}

์ด ๊ฒฝ์šฐ์˜ ์„ฑ๋Šฅ์„ ์žฌ ๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
[bjlee@bjlee-xnote test]$ time ./a.out
real    0m7.683s
user    0m7.104s
sys     0m0.032s
[bjlee@bjlee-xnote test]$

์–ด์จŒ๋˜ stringstream์„ ์“ฐ๊ฒŒ ๋˜๋ฉด ์„ฑ๋Šฅ์€ ๋ฐฐ ์ด์ƒ ๋–จ์–ด์ง€๋Š”๊ตฐ์š”.
๊ทธ๋ ‡๋‹ค๋ฉด Bjarne ์•„์ €์”จ๊ฐ€ int๋ฅผ string์œผ๋กœ ๋ณ€ํ™˜ํ•  ๋•Œ stringstream์„ ์“ฐ๋Š”๊ฒŒ ๊ฐ€์žฅ ๊ฐ„๋‹จํ•˜๋‹ค๊ณ  ์ถ”์ฒœํ•œ ์ด์œ ๋Š” ๋ฌด์—‡์ผ๊นŒ์š”? ์ด์œ ๋„ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. string์„ int๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ์ชฝ์€ ๊ทธ๋Ÿด๋“ฏํ•œ ์†”๋ฃจ์…˜์ด ์ด๋ฏธ ๋งŽ์ด ์žˆ์Šต๋‹ˆ๋‹ค. (atoll์ด๋‚˜ atoi์™€ ๊ฐ™์€) ๊ฑฐ๊ธฐ๋‹ค ์ด๋Ÿฐ ํ•จ์ˆ˜๋“ค์€ '๋” ์ด์ƒ ๊ฐ„๋‹จํ•ด์งˆ ์ˆ˜ ์—†์„ ์ •๋„๋กœ' ๋‹จ์ˆœํ•œ ํ•จ์ˆ˜๋“ค์ด์–ด์„œ, ๊ทธ ํ•จ์ˆ˜๊ฐ€ '๊ทธ๋‹ค์ง€ ์šฐ์•„ํ•ด๋ณด์ด์ง€ ์•Š๋Š”๋‹ค๋Š” ์ด์œ ๋กœ' C++์ ์ธ ํ•ด๊ฒฐ์ฑ…์„ ๊ณ ์•ˆํ•ด ๋‚ธ๋‹ค๋Š” ๊ฒƒ์ด ๋ง์ด ๋˜์งˆ ์•Š์•„์š”. ๋ฐฉ๊ธˆ ์œ„์—์„œ ์‹คํ—˜ํ•œ ๊ฒฐ๊ณผ๋กœ๋„ ์ฆ๋ช…๋˜๋Š” ์ด์•ผ๊ธฐ์ž…๋‹ˆ๋‹ค๋งŒ, ์„ฑ๋Šฅ๋„ ๋” ํ˜•ํŽธ์—†์–ด์งˆ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์ฃ .
๋ฐ˜๋ฉด int๋ฅผ string์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด๋ฉด, ๊ทธ๋‹ค์ง€ ๊ฐ„๋‹จํ•œ ๊ฒƒ์ด ์—†์Šต๋‹ˆ๋‹ค. ์ œ๊ฐ€ ์„ ํ˜ธํ•˜๋Š” ๋ฐฉ๋ฒ•์€ (์œ„์˜ ์˜ˆ์ œ ์ฝ”๋“œ์—์„œ๋„ ์จ๋จน์—ˆ์Šต๋‹ˆ๋‹ค๋งŒ) sprintf๋ฅผ ์“ฐ๋Š” ๊ฒƒ์ธ๋ฐ, ๊ทธ๊ฒƒ๋„ ๋ฒ„ํผ๋ฅผ ์žก๋Š” ๋“ฑ์˜ ์‚ฌ์ „ ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ˆ๊นŒ ๊ทธ๋ ‡๊ฒŒ ํŽธํ•˜์ง€๋Š” ์•Š์•„์š”. ๊ทธ๋Ÿฌ๋‹ˆ ๊ทธ๋Ÿฐ ๊ฒฝ์šฐ์—๋Š” 'stringstream'์„ ์“ฐ๋Š”๊ฒŒ ๋‚˜์„ ์ˆ˜๋„ ์žˆ๊ฒ ์ฃ . Bjarne์˜ ๋ง์ฒ˜๋Ÿผ, '๊ฐ„๋‹จํ•จ'์ด๋ผ๋Š” ๊ฒฌ์ง€์—์„œ ๋ณด๋ฉด ๋ง์ด์—์š”. ๊ฑฐ๊ธฐ๋‹ค stringstream ํด๋ž˜์Šค ์•ˆ์—๋Š” ์˜ค๋งŒ๊ฐ€์ง€ ๋ฐ์ดํ„ฐํƒ€์ž…์„ ๋‹ค ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ์˜ค๋ฒ„๋กœ๋”ฉ๋œ ์—ฐ์‚ฐ์ž๋“ค์ด ์ž”๋œฉ ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์„ฑ๋Šฅ์€ ์•ˆ์ข‹์„์ง€ ๋ชฐ๋ผ๋„, "%lld๊ฐ™์€ ์˜ต์…˜์„ ์ „๋ถ€ ๊ธฐ์–ตํ•˜๊ณ  ์žˆ์ง€ ์•Š์•„๋„ ๊ตฌํ˜„์„ ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ, ํŽธํ•˜๋‹ค๋Š” ๊ฒƒ์ด์ฃ . (๊ฑฐ๊ธฐ๋‹ค template์„ ์„ž์–ด์“ฐ๋ฉด ์•„๋งˆ ๋” ํŽธํ•ด์งˆ๊ฒ๋‹ˆ๋‹ค ใ…‹ใ…‹)
๊ทธ๋ ‡๋‹ค๋ฉด ์˜ค๋Š˜์˜ ๊ฒฐ๋ก ์€...
  • int -> string ๋ณ€ํ™˜์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋Š” stringstream์„ ์“ฐ๋Š” ๊ฒƒ์ด '๊ฐ„๋‹จํ•˜'๋‹ค.
  • ๋ฐ˜๋Œ€์˜ ๋ณ€ํ™˜์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋Š” stringstream์„ ์จ ๋ด์•ผ ์ฝ”๋“œ๊ฐ€ ๊ฐ„๋‹จํ•ด ์ง€์ง€ ์•Š๋Š”๋‹ค
  • ๋‘ ๊ฐ€์ง€ ๊ฒฝ์šฐ ๋ชจ๋‘, C API๋ฅผ ์“ฐ๋Š” ๊ฒƒ์— ๋น„ํ•ด์„œ๋Š” ์„ฑ๋Šฅ์ด ๊ต‰์žฅํžˆ ๋–จ์–ด์ง„๋‹ค

์„ฑ๋Šฅ์ด ๊ฑฑ์ •๋˜์‹ ๋‹ค๋ฉด ๋ญ๋‹ˆ๋ญ๋‹ˆ ํ•ด๋„ C API์ชฝ์ด ๋‚ซ๊ฒ ์–ด์š”.
๋ฐ˜์‘ํ˜•

์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•
arcsin arccos ๋“ฑ๋“ฑ์„ ๊ตฌํ•  ์ˆ˜ ์žˆ์Œ.
๋ฐ˜์‘ํ˜•

์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•
in Judge Queue๋กœ ์ธํ•ด ์•„์ง ํŒ๋‹จ๋ชปํ•œ ๋‚ด๊ฐ€ ํ‘ผ ์†Œ์Šค


2007/2008 ACM International Collegiate Programming Contest
University of Ulm Local Contest

Problem A: Annoying painting tool

Maybe you wonder what an annoying painting tool is? First of all, the painting tool we speak of supports only black and white. Therefore, a picture consists of a rectangular area of pixels, which are either black or white. Second, there is only one operation how to change the colour of pixels:

Select a rectangular area of r rows and c columns of pixels, which is completely inside the picture. As a result of the operation, each pixel inside the selected rectangle changes its colour (from black to white, or from white to black).

Initially, all pixels are white. To create a picture, the operation described above can be applied several times. Can you paint a certain picture which you have in mind?

Input Specification

The input contains several test cases. Each test case starts with one line containing four integers n, m, r and c. (1 โ‰ค r โ‰ค n โ‰ค 100, 1 โ‰ค c โ‰ค m โ‰ค 100), The following n lines each describe one row of pixels of the painting you want to create. The ith line consists of m characters describing the desired pixel values of the ith row in the finished painting ('0' indicates white, '1' indicates black).

The last test case is followed by a line containing four zeros.

Output Specification

For each test case, print the minimum number of operations needed to create the painting, or -1 if it is impossible.

Sample Input

3 3 1 1
010
101
010
4 3 2 1
011
110
011
110
3 4 2 2
0110
0111
0000
0 0 0 0

Sample Output

4
6
-1
๋ฐ˜์‘ํ˜•

์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

๋ณ€์ˆ˜์˜ ์ตœ์†Œ ์ตœ๋Œ€๊ฐ’ ์„ค์ •
ํ• ์ˆ˜์žˆ๋‹ค.

์ „๋ฐฉ์„ ์–ธ!!!!!!
class ๋ธ”๋ผ๋ธ”๋ผ;

๋’ค์— ๋ทฐํด๋ž˜์Šค์—์„œ ๋‹ค์ด์•Œ๋กœ๊ทธ๋ฅผ ์ธํด๋ฃจ๋“œ

๋‹ค์ด์•Œ๋กœ๊ทธ์—์„œ ๋ทฐํด๋ž˜์Šค์—์„œ ์ธํด๋ฃจ๋“œ

๊ณ ๋กœ ์‚ฅ๊ธ€์‚ฅ๊ธ€ ๋ˆ๋‹ค.

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ณ ์ž ์ „๋ฐฉ์„ ์–ธ์„ ํ•œ๋‹ค.

(์‚ฌ์‹ค์€ ์ž˜ ๋ชป ์งœ์—ฌ์ง„ ๊ตฌ์กฐ)

๊ทธ๋Ÿฌ๋‚˜ MFC์—์„œ ์ด๋ ‡๊ฒŒ ์ œ๊ณต์„ํ•˜๊ธฐ๋•Œ๋ฌธ์—

์ผ์ข…์˜ ํŠธ๋ฆญ์„ ์จ์„œ ์ด๋Ÿฐ ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

---
์ƒ์„ฑ์ž๋ณด๋‹ค ๋ฆฌ์†Œ์Šค๊ฐ€ ๋งŒ๋“ค์–ด์ง€๋Š”๊ฒŒ ๋” ๋Š๋ฆฌ๋ฏ€๋กœ

๋งŒ๋“ค์–ด์ง€์ง€๋„ ์•Š์•˜๋Š”๋ฐ ์ดˆ๊ธฐํ™”ํ• ๋ ค๋ฉด ์—๋Ÿฌ!

๊ทธ๋ž˜์„œ WM_INITDIALOG ๋ฉ”์‹œ์ง€ ๋ฐœ์ƒ. ์—ฌ๊ธฐ์„œ ์ดˆ๊ธฐํ™”.


์ฐธ๊ณ ๋กœ. ON์ด๋ถ™๋Š” ํ•จ์ˆ˜๋Š” ๋ฉ”์‹œ์ง€์—์„œ ์˜จ ํ•จ์ˆ˜์ด๋‹ค!!!


๋ฐ˜์‘ํ˜•

+ Recent posts