본문 바로가기

Algorithm/Math

(C++) - 백준(BOJ) 6768번 : Don’t pass me the ball!

반응형

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

조합 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

골을 넣은 플레이어의 번호 n을 선언 후 입력받습니다. 

 

📔 풀이과정

 골을 넣은 플레이어는 4명 중 가장 높은 수를 가지고 있습니다. 따라서 이 결과가 바뀌지 않으려면 1 ~ n -1의 번호들 중 3명의 플레이어를 결정하면 됩니다. 따라서 조합을 생각하게 되며 n-1C3의 값을 출력하면 됩니다.

 

 

📔 정답출력

n-1C3의 결과를 출력합니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int n, ans = 1;
int main(){
    cin >> n;
    for(int i = 1; i <= 3; i++) ans *= n - i;
    cout << ans / 6;
}