ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

14697๋ฒˆ: ๋ฐฉ ๋ฐฐ์ •ํ•˜๊ธฐ

์ •๋ณด ์ดˆ๋“ฑํ•™๊ต 6ํ•™๋…„ ์—ฌํ•™์ƒ๋“ค์€ ๋‹จ์ฒด๋กœ 2๋ฐ• 3์ผ ์ˆ˜ํ•™์—ฌํ–‰์„ ๊ฐ€๊ธฐ๋กœ ํ–ˆ๋‹ค. ํ•™์ƒ๋“ค์ด ๋ฌต์„ ์ˆ™์†Œ์—๋Š” ๋ฐฉ์˜ ์ •์›(๋ฐฉ ์•ˆ์— ์žˆ๋Š” ์นจ๋Œ€ ์ˆ˜)์„ ๊ธฐ์ค€์œผ๋กœ ์„ธ ์ข…๋ฅ˜์˜ ๋ฐฉ์ด ์žˆ์œผ๋ฉฐ, ๊ฐ™์€ ์ข…๋ฅ˜์˜ ๋ฐฉ๋“ค์ด ์—ฌ๋Ÿฌ

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ Go

// https://www.acmicpc.net/problem/14697v
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var a, b, c, n int
	fmt.Fscanln(reader, &a, &b, &c, &n)
	fmt.Fprintln(writer, checkRooms(a, b, c, n))
}

func checkRooms(a, b, c int, n int) int {
	for i := 0; i <= n; i++ {
		for j := 0; j <= n-i; j++ {
			for k := 0; k <= n-i-j; k++ {
				if a*i+b*j+c*k == n {
					return 1
				}
			}
		}
	}
	return 0
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/14697
import sys

def check_rooms(a, b, c, n):
    for i in range(0, n+1):
        for j in range(0, n+1-i):
            for k in range(0, n+1-i-j):
                if a*i + b*j + c*k == n:
                    return 1
    return 0

if __name__ == "__main__":
    a, b, c, n = list(map(int, sys.stdin.readline().split()))
    print(check_rooms(a, b, c, n))
728x90
๋Œ“๊ธ€