728x90
3533번: Explicit Formula
Consider 10 Boolean variables x1, x2, x3, x4, x5, x6, x7, x8, x9, and x10. Consider all pairs and triplets of distinct variables among these ten. (There are 45 pairs and 120 triplets.) Count the number of pairs and triplets that contain at least one variab
www.acmicpc.net
문제 풀이
이 문제는 텍스트의 길이만 보고는 살짝 당황스러울 수 있는데, 결국에는 정확하게 반복문을 통해 풀어주면 쉽게 풀 수 있었다. (브론즈 3 문제라 더욱 간단한 방법이 있을수도 있다..)
2개 혹은 3개의 수를 뽑아 or 연산을 수행하고, 연산 결과 간에는 xor연산을 수행해준다. 요소 2, 3개를 빠짐없이 뽑아주기 위해 combinations를 사용했다.
정답 코드
from itertools import combinations
lst = list(map(int, input().split()))
first = True
for i in combinations(lst, 2) :
if first :
result = i[0] or i[1]
first = False
else :
tmp = (i[0] or i[1])
if result == tmp : result = False
else : result = True
for i in combinations(lst, 3) :
tmp = i[0] or i[1] or i[2]
if result == tmp : result = False
else : result = True
if result : print(1);
else : print(0)
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 4084 - Viva la Diferencia [python] (0) | 2023.03.08 |
---|---|
[BOJ/백준] 3578 - Holes [python] (0) | 2023.03.08 |
[BOJ/백준] 3507 - Automated Telephone Exchange [python] (0) | 2023.03.07 |
[프로그래머스] 개인정보 수집 유효기간 [python] (0) | 2023.03.07 |
[BOJ/백준] 26546 - Reverse [python] (0) | 2023.03.06 |