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

2-kangrae-jo #6

Merged
merged 2 commits into from
Oct 28, 2024
Merged

2-kangrae-jo #6

merged 2 commits into from
Oct 28, 2024

Conversation

kangrae-jo
Copy link
Collaborator

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

https://school.programmers.co.kr/learn/courses/30/lessons/42842

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

20m

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

ย ๋ฌธ์ œ๊ฐ€ ์™„์ „ํƒ์ƒ‰์œผ๋กœ ๋ถ„๋ฅ˜๋˜์–ด์„œ์ธ์ง€ ๋ฌธ์ œ์˜ ํฌ์ธํŠธ๋ฅผ ํ•œ ๋ฒˆ์— ์ž˜ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.
์ผ๋‹จ brown ๋˜๋Š” yellow์˜ ํ•œ ๋ณ€์˜ ๊ธธ์ด๋ฅผ a, ๋‹ค๋ฅธ ํ•œ ๋ณ€์˜ ๊ธธ์ด๋ฅผ b๋ผ๊ณ  ํ–ˆ์„ ๋•Œ,
a๋ฅผ 1์”ฉ ๋Š˜๋ ค๊ฐ€๋ฉฐ b๋ฅผ ๋น„์œจ์— ๋งž๊ฒŒ ์„ค์ •ํ•˜๊ณ  ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” a์™€ b๋ฅผ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด ํ•ต์‹ฌ์ด๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค.

ย ์—ฌ๊ธฐ์„œ ๋˜ ํ•˜๋‚˜ ๋” ํฌ์ธํŠธ๋Š” yellow๋ฅผ ๊ฐ์‹ธ๋Š” brown์„ a์™€ b๋กœ ๋‚˜๋ˆ„๋Š” ๊ฒƒ์ด ์ƒ๊ฐํ•˜๊ธฐ๋„ ํŽธํ•˜๊ณ  ์ „์ฒด ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ์ ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.
์ž‘์„ฑ๋œ ์ˆ˜๋„์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  1. for a๋ฅผ 1๋ถ€ํ„ฐ (brown+4)/2๊นŒ์ง€
    1-1. b๋ฅผ (brown+4)/2-a ๋กœ ์„ค์ •
    1-2. ํ˜„์žฌ (a-2)*(b-2)๋กœ ๊ณ„์‚ฐ๋œ ๊ฐ’์ด yellow์™€ ๋™์ผํ•œ์ง€ ํ™•์ธ
    1-3. ๋™์ผํ•˜๋‹ค๋ฉด break;
    1-4. ์•„๋‹ˆ๋ผ๋ฉด ๋‹ค์‹œ 1๋ฒˆ์œผ๋กœ

ย (brown+4)/2๊นŒ์ง€ ๋ฐ˜๋ณตํ•˜๋Š” ์ด์œ ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
์ „์ฒด brown์˜ ์ˆ˜๊ฐ€ 10์ธ 3*4carpet์—์„œ ๊ฐ ๋ณ€์„ ๊ธฐ์ค€์œผ๋กœ ๊ฐœ์ˆ˜๋ฅผ ์…€๋•Œ๋Š” 14๊ฐœ์ด๋‹ค.
์™œ๋ƒํ•˜๋ฉด 4๊ฐœ์˜ ๊ผญ์ง“์ ์— ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
๊ทธ ์ค‘ ์ ˆ๋ฐ˜์—์„œ a์™€ b๋ฅผ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋‚˜๋ˆ„๊ธฐ 2๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

ย ์ž‘์„ฑ๋œ ์ˆ˜๋„์ฝ”๋“œ๋Š” ๋งค์šฐ ๊ฐ„๋‹จํ•˜์ง€๋งŒ, ๊ทธ๋ฆผ์ด ์žˆ์œผ๋ฉด ๋” ๋น ๋ฅธ ์ดํ•ด์— ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์•„์„œ ์ฒจ๋ถ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

image

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

ย ์˜ค๋žœ๋งŒ์— ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” ๊ฑฐ๋ผ ์–ด๋–ค ๋‚œ์ด๋„์˜ ๋ฌธ์ œ๋ฅผ ์ •ํ• ์ง€ ๊ณ ๋ฏผ์ด ๋งŽ์ด ๋ฉ๋‹ˆ๋‹ค.
๋‹ค์Œ์—๋Š” 1h์ •๋„ ๊ณ ๋ฏผํ•  ์ˆ˜ ์žˆ๋Š” ์ˆ˜์ค€์˜ ๋ฌธ์ œ๋ฅผ ๊ฐ€์ ธ์˜ค๊ฒ ์Šต๋‹ˆ๋‹ค!!

Copy link
Collaborator

@g0rnn g0rnn 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

Choose a reason for hiding this comment

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

์ €๋„ ํ•œ๋ฒˆ ํ’€์–ด๋ดค์Šต๋‹ˆ๋‹น

์ฝ”๋“œ ๋ณด๊ธฐ
#include <string>
#include <vector>

using namespace std;

vector<int> solution(int brown, int yellow) {
    vector<int> answer;
    int a, b; 

    // brown์€ ํ•ญ์ƒ 2์˜ ๋ฐฐ์ˆ˜์ด๋ฏ€๋กœ ์†Œ์ˆซ์  ๊ฑฑ์ •์€ ์•ˆํ•ด๋„ ๋œ๋‹ค
    for(a =1;a<(brown+4)/2;a++) {
        b = (brown+4)/2 - a;
        if(yellow == (a-2)*(b-2)) break;  
    }
    answer.push_back(b);
    answer.push_back(a);
    return answer;
}

Copy link
Collaborator

@wnsmir wnsmir left a comment

Choose a reason for hiding this comment

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

์ฒ˜์Œ์— ์‚ด์ง ๊ฐ์ด์•ˆ์žกํ˜€ ๊ณฐ๊ณฐํžˆ ์ƒ๊ฐํ•ด๋ณด๋‹ˆ๊นŒ ๊ฒฝ์šฐ์˜์ˆ˜๊ฐ€ ์ •ํ•ด์ ธ์žˆ๋”๋ผ๊ตฌ์š”
๋‘˜๋Ÿฌ์‹ธ๋ฉด์„œ ๊ฐ€๋กœ๊ฐ€ ๋” ๊ธด์Œ์˜ ์กฐ๊ฑด์„ ๋ฏธ์ง€์ˆ˜ ๋‘๊ฐœ, brown yellow ๋‘๊ฐœ๋ฅผ ์ด์šฉํ•ด
ํ–‰๊ณผ ์—ด์˜ ๊ฐœ์ˆ˜๋ฅผ ๋ฏธ์ง€์ˆ˜๋กœ ์žก๊ณ  ๋‘˜๋Ÿฌ์‹ธ๋ฉด์„œ ๋‚˜ํƒ€๋‚˜๋Š” ์กฐ๊ฑด ๋‘๊ฐ€์ง€๋ฅผ ์‹์— ๋Œ€์ž…ํ•ด ๋ชจ๋“  ํ–‰๊ณผ ์—ด ์Œ์„
๋ธŒ๋ฃจํŠธํฌ์Šค๋กœ ๋Œ์•„๊ฐ€๋ฉฐ ์กฐ๊ฑด์— ์ผ์น˜ํ•˜๋Š” ์Œ๋งŒ ๋ฝ‘์•„๋‚ด๋Š” ๋ฐฉ์‹์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค.

25๋ถ„์ •๋„ ๊ฑธ๋ฆฐ๊ฒƒ๊ฐ™์Šต๋‹ˆ๋‹ค!

def solution(brown, yellow):
    
    ans = []
    answer = []
    for r in range(brown + yellow):
        c = (brown + yellow) / (r+1)
        if brown == 2 * (r+1) + (2 * c - 4) and yellow == (r-1) * (c-2):
            ans.append(c)
            ans.append(r + 1) 
    row, col = ans[0], ans[1]
    
    answer.append(row)
    answer.append(col)
    
    return answer

@kokeunho
Copy link
Collaborator

์ €๋Š” ์ด ํƒ€์ผ์˜ ๊ฐฏ์ˆ˜๋ฅผ ๊ตฌํ•˜๊ณ  ์•ฝ์ˆ˜๋ฅผ ๊ตฌํ•˜์—ฌ ํ’€์–ด๋ดค์Šต๋‹ˆ๋‹ค.

def solution(brown, yellow):
    total = brown + yellow
    
    for i in range(1, int(total**0.5) +1 ):
        if total % i == 0:
            height = i
            width = total / height
            if (height - 2) * (width - 2) == yellow:
                answer = [width, height]
    return answer

for๋ฌธ์—์„œ ์•ฝ์ˆ˜๋ฅผ ์ฐพ๋Š”๋ฐ
i๋ถ€ํ„ฐ total๊นŒ์ง€ ๋‹ค ๋Œ์•„์„œ ์•ฝ์ˆ˜ ์Œ์„ ์ฐพ๊ณ ๋‚œ ํ›„, ๊ฐ€๋กœ๊ฐ€ ์„ธ๋กœ๋ณด๋‹ค ๊ธด ๊ฒฝ์šฐ๋ฅผ ๋‹ค์‹œ ๊ฑธ๋Ÿฌ๋‚ด๋„ ๋˜์ง€๋งŒ
i๋ถ€ํ„ฐ total์˜ ์ œ๊ณฑ๊ทผ๊นŒ์ง€๋งŒ ๋Œ๋ฉด ๋” ๊ธด ์ชฝ์„ ๋ฐ”๋กœ ๊ฐ€๋กœ์— ๋Œ€์ž…ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑธ ์•Œ์•˜์Šต๋‹ˆ๋‹ค.
๊ทธ ๋’ค๋กœ๋Š” ๊ฐ•๋ž˜๋‹˜ ์ฝ”๋“œ์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.
์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค~

@kangrae-jo kangrae-jo merged commit 48210b7 into main Oct 28, 2024
1 check passed
@kangrae-jo kangrae-jo deleted the 2-kangrae-jo branch October 28, 2024 04:13
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.

4 participants