-
Notifications
You must be signed in to change notification settings - Fork 2
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
51-xxubin04 #194
51-xxubin04 #194
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฒจ์ (int((d**2 - (a*k)**2)**0.5/k) + 1)
์ด๊ฒ ๋์ฒด ๋ฌด์จ ์์ธ๊ฐ... ํ๋๋ฐ
d = sqrt((a*k)**2 + (b*k)**2)
์์ b๋ง ๋จ๊ธฐ๋๋ก ๋ณํํ ์์ด์๊ตฐ์... ํํ
๋ ์ด ๊ฐ ์๋ก ์ํ ๋จธ๋ฆฌ๊ฐ ํดํํ๋ ๊ฒ ๊ฐ์์ ๐ฅน
์ ๋ ํฐ ์ฐจ์ด๋ ์๊ณ , ๋ฐ๋ณต๋ฌธ ๋ณ์์ step ์ ๋๋ง ๋ฐ๊ฟจ๋ค์ฉ
def solution(k, d):
answer = 0
th = d**2
for a in range(0, d + 1, k):
b = int((th - a**2)**0.5 / k + 1)
answer += b
return answer
xxubin04/์ํ/์ ์ฐ๊ธฐ.py
Outdated
@@ -0,0 +1,7 @@ | |||
def solution(k, d): | |||
answer = 0 | |||
a = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ์๊ฐํด๋ณด๋ฉด, for๋ฌธ์ i
๋ณ์๊ฐ a์ ๋์ผํ ์ญํ ์ ํ๋ค๋ ๊ฒ์ ์ ์ ์์ต๋๋ค :)
xxubin04/์ํ/์ ์ฐ๊ธฐ.py
Outdated
answer = 0 | ||
a = 0 | ||
for i in range(int(d/k)+1): | ||
answer += (int((d**2 - (a*k)**2)**0.5/k) + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d**2
์ฐ์ฐ ๊ฒฐ๊ณผ๋ ๋ฐ๋ณต๋ฌธ ๋ด์์ ๋ถ๋ณ์ด์ฃ ? ๊ทธ๋ ๋ค๋ฉด ๋ฐ๋ณต๋ฌธ ๋ฐ์์ ๋ฏธ๋ฆฌ ๊ณ์ฐํด๋๋ ๊ฑธ๋ก ์ต์ ํ ํด๋ด
์๋ค :)
threshold = d ** 2
for a in range(int(d/k) + 1):
answer += (int((threshold - (a*k)**2)**0.5 / k) + 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋์ฃผ์ด์ง d ๋ฒ์ ์์ ์ ๊ทผ๊ฐ๋ฅํ x์ ์ต๋๊ฐ์ ๊ตฌํ๊ธฐ ์ํด dSquared - x^2๋ฅผ ๊ณ์ฐํด์ ๊ฐ๋ฅํ ๋ฒ์๋ฅผ ๊ตฌํ์ด์
๊ทธ๋ฆฌ๊ณ y ์ต๋๊ฐ์ k ๊ฐ๊ฒฉ์ผ๋ก ๋๋์ด ๊ฐ๋ฅํ x์ ๊ฐ์๋ฅผ ์ธ๊ณ , ์ด๋ฅผ count์ ๋ํ์ต๋๋ค!
class Solution {
public static long solution(int k, int d) {
long count = 0;
long dSquared = (long) d * d;
for (int x = 0; x <= d; x += k) {
long maxXSquared = dSquared - (long) x * x;
int maxX = (int) Math.sqrt(maxXSquared);
count += (maxX / k) + 1;
}
return count;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import math
def solution(k, d):
answer = 0
for i in range(0, d+1, k):
length = int(math.sqrt(pow(d, 2)-pow(i, 2)))
answer += (length//k) + 1
return answer
๊ฑฐ์ ๋์ผํ์ง๋ง... ์ ๋ math ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ sqrt(๋ฃจํธ)ํจ์๋ฅผ ๊ฐ์ ธ์์ ์ผ์ต๋๋ค!
xxubin04/์ํ/์ ์ฐ๊ธฐ.py
Outdated
answer = 0 | ||
a = 0 | ||
for i in range(int(d/k)+1): | ||
answer += (int((d**2 - (a*k)**2)**0.5/k) + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฃจํธ๋ 0.5 ์ ๊ณฑํ๋ฉด ์ฌ์ฉํ ์ ์์๋ค์..!
๐ ๋ฌธ์ ๋งํฌ
ํ๋ก๊ทธ๋๋จธ์ค - ์ ์ฐ๊ธฐ
โ๏ธ ์์๋ ์๊ฐ
20๋ถ
์๊ฐ๋ณด๋ค ๋๋ฌด ์ฝ๊ฒ ํ์ด์ ๊ฐ๋จํ๊ฒ ์ฌ๋ฆฌ๊ฒ ์ต๋๋ค..!
โจ ์๋ ์ฝ๋
์ฒ์์๋ ๋จ์ํ๊ฒ ์์ ๊ณผ ํ ์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ์ ๊ณต์์ธ (a^2 + d^2)^0.5๋ฅผ ์ฌ์ฉํด์ a=0๋ถํฐ a=d/k๊น์ง ํ์ธํด์ฃผ๋ ๊ณผ์ ์ ๊ฑฐ์ณค๋๋ฐ ์๊ฐ์ด๊ณผ๊ฐ ๋ด๋ค...
0๋ถํฐ
int(d/k)
๊น์ง์ a๋ฅผ for๋ฌธ์ผ๋ก ์ํํ๋ค. (int(d/k)
= ๊ฑฐ๋ฆฌ d๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์ต๋ ak๋ฅผ ๋ง์กฑํ๋ a)(int((d**2 - (a*k)**2)**0.5/k) + 1)
๋ ๊ฑฐ๋ฆฌ d๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์ต๋ bk๋ฅผ ๋ง์กฑํ๋ b์ 1์ ๋ํ ์์ด๋ค. 1์ b์ ์ขํ 0์ ์ํด ์ถ๊ฐํด์ค ๊ฒ์ด๋ค.์กฐ๊ฑด์ ๋ง์กฑํ๋์ง ๋ชจ๋ ์ ์ ์ขํ์์์ ๊ฑฐ๋ฆฌ๋ฅผ ํ์ธํด์ฃผ๋ ๊ฒ์ด ์๋, ๊ฑฐ๋ฆฌ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์ต๋ ์ ์ขํ๋ฅผ ๊ฐ์๋ก์ ๋ํด์ฃผ๋ฉด ์๊ฐ์ด๊ณผ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ค..!
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
์ ์กฐ๊ฑด๋ง ์ ์ธ์์ฃผ๋ฉด ์ฝ๊ฒ ํ ์ ์์ด์ ์ฌ๋ ค๋ ๋๋์ง ๊ณ ๋ฏผํ๊ธด ํ์ง๋ง ์ฌ๋ฆฝ๋๋ค~!