다음과 같이 코드를 만들면 된다.
1
2
3
4
5
6
7
8
9
|
from itertools import combinations
num = int(input())
nums = []
for i in range(1, num):
nums.append(i)
# print(nums)
combis = list(combinations(nums, 3))
# print(combis)
print(len(combis))
|
cs |
이전에 https://gettingtoknowit.tistory.com/129?category=919340 에서 combination 함수를 사용했던 적이 있다.
[백준] 2798_블랙잭 파이썬 (combination함수 vs 3중for문)
1번 방법: combination함수 우선 상당히 복잡하게 푼 방법부터 보이자면 다음과 같다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 from itertools import combinations N, M = map(int,..
gettingtoknowit.tistory.com
똑같이 이번 문제에서도 사용하면 된다.
그리고 중요한 부분은 언제나 그렇듯 "입력값"을 제대로 아는 것이다.
입력값을 보면 "The input will be the positive integer J (1 ≤ J ≤ 99), which is the jersey number of the goal scorer."라고 되어있다.
즉, goal scorer의 번호를 입력하기 때문에, 4명 중 마지막 4번째 사람의 번호를 입력한다는 뜻이고,
문제의 조건에 따라 마지막 1명은 항상 고정된 숫자로 만든다면,결국 조합은 3명의 조합의 갯수만 구하면 된다! (그래서 7행을 보면 3만 뽑아서 쓴다)
문제 출처: https://www.acmicpc.net/problem/6768
6768번: Don’t pass me the ball!
A CCC soccer game operates under slightly different soccer rules. A goal is only counted if the 4 players, in order, who touched the ball prior to the goal have jersey numbers that are in strictly increasing numeric order with the highest number being the
www.acmicpc.net
'코딩 문제풀이 및 연습 > Python 연습' 카테고리의 다른 글
[백준] 11399_ATM 파이썬 (그리디 알고리즘 / 정렬) (0) | 2021.10.07 |
---|---|
[백준] 13305_주유소 파이썬 (그리디 알고리즘) (0) | 2021.10.07 |
[백준] 7568_덩치 파이썬 (0) | 2021.09.27 |
[백준] 2798_블랙잭 파이썬 (combination함수 vs 3중for문) (0) | 2021.09.26 |
[백준] 5532_방학 숙제 파이썬 (if-else vs ceil함수) (0) | 2021.09.22 |