ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1004
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var t int
fmt.Fscanln(reader, &t)
for i := 0; i < t; i++ {
var count int
var startX, startY, endX, endY, n int
fmt.Fscanln(reader, &startX, &startY, &endX, &endY)
fmt.Fscanln(reader, &n)
for j := 0; j < n; j++ {
var planetX, planetY, r int
fmt.Fscanln(reader, &planetX, &planetY, &r)
isStartContained := checkPlanetContains(startX, startY, planetX, planetY, r)
isEndContained := checkPlanetContains(endX, endY, planetX, planetY, r)
if isEndContained && !isStartContained || !isEndContained && isStartContained {
count++
}
}
fmt.Fprintln(writer, count)
}
}
func checkPlanetContains(x, y, planetX, planetY, r int) bool {
dist := (x-planetX)*(x-planetX) + (y-planetY)*(y-planetY)
if dist > r*r {
return false
}
return true
}
๐จ Python3
# https://www.acmicpc.net/problem/1004
import sys
def check_planet_contains(x, y, planet_x, planet_y, r):
dist = (x-planet_x)**2 + (y-planet_y)**2
if dist > r*r:
return False
return True
if __name__ == "__main__":
t = int(sys.stdin.readline())
for i in range(t):
count = 0
start_x, start_y, end_x, end_y = list(map(int, sys.stdin.readline().split()))
n = int(sys.stdin.readline())
for j in range(n):
planet_x, planet_y, r = list(map(int, sys.stdin.readline().split()))
is_start_contained = check_planet_contains(start_x, start_y, planet_x, planet_y, r)
is_end_contained = check_planet_contains(end_x, end_y, planet_x, planet_y, r)
if is_end_contained and not is_start_contained or not is_end_contained and is_start_contained:
count += 1
print(count)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 9095๋ฒ / 1, 2, 3 ๋ํ๊ธฐ [Go][Python3] (0) | 2021.01.10 |
---|---|
BOJ / 1024๋ฒ / ์์ด์ ํฉ [Go][Python3] (0) | 2021.01.09 |
BOJ / 11719๋ฒ / ๊ทธ๋๋ก ์ถ๋ ฅํ๊ธฐ 2 [Go][Python3] (0) | 2021.01.07 |
BOJ / 18243๋ฒ / Small World Network [Go][Python3] (0) | 2021.01.06 |
BOJ / 11265๋ฒ / ๋๋์ง ์๋ ํํฐ [Go][Python3] (0) | 2021.01.05 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- Algorithm
- python3
- Macbook pro 2012 mid 13
- ๋งฅ๋ถ
- ๋ถํ ์ ๋ณต
- ํ๋ก์ด๋์์ฌ
- baekjoon
- ์คํ
- ๋งฅ๋ถํ๋ก
- dfs
- BFS
- ๋ธ๋ฃจํธํฌ์ค
- ๋ชฝ๊ณ ๋๋น
- ํ
- ๋ฐฑ์ค
- dp
- go
- Golang
- ์ด๋ถํ์
- ํด์๋งต
- ballet
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ์๊ฐ๊ต์ฒด
- BOJ
- AWS
- MongoDB
- java
- ๋ฐ๋
- ์๋ฐ
- ์๊ณ ๋ฆฌ์ฆ
- Total
- Today
- Yesterday