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

30-H0ngJu #248

Merged
merged 1 commit into from
Oct 10, 2024
Merged

30-H0ngJu #248

merged 1 commit into from
Oct 10, 2024

Conversation

H0ngJu
Copy link
Collaborator

@H0ngJu H0ngJu commented Sep 27, 2024

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

Fly me to the Alpha Cenauri

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

2H

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

image

๋ฌธ์ œ ์ž…๋ ฅ ์กฐ๊ฑด์„ ๋ณด๋ฉด,
0 โ‰ค x < y < 2**31

'์•„ ์ด๊ฑด ๋ญ”๊ฐ€ ํƒ์ƒ‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์ ˆ๋Œ€ ์•„๋‹ˆ๊ฒ ๋‹ค'๋ผ๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.


๊ทธ๋ž˜์„œ ๊ฑฐ๋ฆฌ๊ฐ€ 2~8๊นŒ์ง€ ์ญ‰ ๋ดค๋Š”๋ฐ์š”
image


๊ฑฐ๋ฆฌ๊ฐ€ 2์ผ๋•Œ ๋นผ๊ณ  2๋ฒˆ์”ฉ ๋ฐ˜๋ณต ๋˜๋Š”๊ตฌ๋‚˜ํ•˜๊ณ 
์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.

๋ญ”๊ฐ€.. ๊ณจ๋“œ 5 ์น˜๊ณ  ๋ฌธ์ œ๊ฐ€ ์‰ฌ์›Œ์„œ '๋‹ค๋ฅธ ๋ฌธ์ œ ํ•˜๋‚˜ ๋” ํ’€๊นŒ?' ํ–ˆ๋Š”๋ฐ์š”,
๊ทธ๋Œ€๋กœ 2์‹œ๊ฐ„ ๋™์•ˆ ๋ณด๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

image


image

์ผ๋‹จ ์ด๋Ÿฐ์‹์œผ๋กœ ๊ฐ€์ง€๋ฅผ ์น˜๋ฉด์„œ ์ƒ๊ฐํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

๋งˆ์ง€๋ง‰ ์ฆ๊ฐ€๋„ 1์ด๋ผ๋ฉด, ๊ทธ์ „์—๋Š” 2๊ฐ€ ๋‚˜์™€์•ผ ํ•˜๊ณ , ๋˜ ๊ทธ ์ „์—๋Š” 3์ด ๋‚˜์™€์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ฒ˜์Œ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค.
์ฒซ ์‹œ์ž‘์ด ์ฆ๊ฐ€๊ฐ€ 1์ด๋ผ๋ฉด, ๊ทธ ํ›„์—๋Š” 2, 3, ... (๊ฑฐ๋ฆฌ๊ฐ€ ๋ฉ€๋‹ค๋ฉด) ์ด๋ ‡๊ฒŒ ์ฆ๊ฐ€ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋ฉด ์ฆ๊ฐ€ํ•˜๋Š” ๊ตฌ๊ฐ„ + ๊ฐ์†Œํ•˜๋Š” ๊ตฌ๊ฐ„์ด ๋ฌธ์ œ์˜ ๋‹ต์ด๋  ๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.



ํ•˜์ง€๋ฉด ์—ฌ๊ธฐ์„œ ๊ทธ ๊ตฌ๊ฐ„๋“ค์„ ์–ด๋–ป๊ฒŒ ๊ตฌํ•  ๊ฒƒ์ธ๊ฐ€? ๊ฐ€ ์ƒ๊ฐ์ด ์•ˆ๋‚˜๋”๋ผ๊ณ ์š”

๊ทธ๋ž˜์„œ ๋…ธ๊ฐ€๋‹ค๋กœ ์ญ‰ ์ ์–ด๋ดค์Šต๋‹ˆ๋‹ค.



๊ทผ๋ฐ ์›ฌ๊ฑธ

์ฒ˜์Œ์— ์ด๋™ ํšŸ์ˆ˜๊ฐ€ 2๋ฒˆ์”ฉ ๋ฐ˜๋ณต๋˜๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ์ ์  ์ฆ๊ฐ€ํ•˜๋”๋ผ๊ณ ์š”.

๊ทœ์น™๋“ค์„ ๋‚˜์—ดํ•ด๋ณด๋ฉด ์‚ฌ์ง„๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

image


n**2 ~ n*(n+1)๋กœ ๋ชจ๋“  ๊ตฌ๊ฐ„์„ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

2**n ๊ฑฐ๋ฆฌ ์ดํ›„ ๋ถ€ํ„ฐ ์ด๋™ ํšŸ์ˆ˜๊ฐ€ +1์ด ๋˜๊ณ ,
n*(n+1) ๊ฑฐ๋ฆฌ ์ดํ›„๋ถ€ํ„ฐ ์ด๋™ ๋ฐ˜๋ณต ํšŸ์ˆ˜๊ฐ€ +1์ด ๋˜๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


๊ทธ๋ ‡๊ฒŒ ๊ตฌ๊ฐ„์„ ๋‚˜๋ˆ ์„œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ผ๋‹จ n**2 ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๊ฐ„์„ ๋‚˜๋ˆ„๊ณ 
๊ทธ ์ค‘์—์„œ n*(n+1)์„ ๊ธฐ์ค€์œผ๋กœ ๋‹ค์‹œ ๋‚˜๋ˆ  ๊ณ„์‚ฐํ•˜์˜€์Šต๋‹ˆ๋‹ค
์—ฌ๊ธฐ์„œ ๋‹ค๋ฅธ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ์ฐธ๊ณ ํ•˜์˜€์”๋‹ˆ๋‹ค


import sys

def input() : return sys.stdin.readline().rstrip()

T = int(input())

for _ in range(T):
    x, y = map(int, input().split())
    distance = y - x
    cnt = 0

    for _ in range(distance+1):
        if distance <= cnt**2:
            break
        else:
            cnt += 1
    
    if distance <= (cnt-1)*cnt:
        print((cnt-1)*2)
    else:
        print(cnt*2-1)

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

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

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

n = int(input())
example = []
for x in range(n):
    example.append(list(map(int,input().split())))

from collections import deque

for y in example:
    
    distance = y[1] - y[0]

    temp1 = int((distance**0.5))
    temp2 = temp1**2

    if distance <=3 :
        print(distance)

    elif distance == temp2:
        print(2*temp1-1)

    elif distance > temp2 and distance <= temp2+temp1:
        print(2*temp1)
        
    elif distance > temp2+temp1 and distance < (temp1+1)**2:
        print(2*temp1+1)

ํ™์ฅฌ๋ฅด!!!!!!!!!!!!!!!! ์˜ค๋žœ๋งŒ์ด์—์š”!!!!!

์—ฅ ๊ทผ๋ฐ ์œ„์— ์ฝ”๋“œ 1๋…„์ „์— ํ’€์—ˆ๋˜ ์ฝ”๋“œ์ธ๋ฐ ๋ญ”์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค

๋‹ค์‹œ ํ•จ ํ’€์–ด๋ด์•ผ์ง€

@tgyuuAn tgyuuAn removed the request for review from alstjr7437 October 10, 2024 15:04
@H0ngJu H0ngJu merged commit 7d102be into main Oct 10, 2024
12 checks passed
@H0ngJu H0ngJu deleted the 30-H0ngJu branch October 10, 2024 17:22
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.

2 participants