[백준 6768] Don’t pass me the ball! (C#, C++) - soo:bak
작성일 :
문제 링크
6768번 - Don’t pass me the ball!
설명
번호가 엄격히 증가하는 4명이 공을 터치해 골을 넣는 경우의 수를 구하는 문제입니다.
마지막 터치 선수가 j번이면, 1부터 j-1 중 세 명을 고르는 조합입니다.
접근법
j-1명 중 3명을 고르는 조합 C(j-1, 3)을 계산합니다.
j가 4 미만이면 경우의 수는 0입니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
using System;
class Program {
static void Main() {
var j = int.Parse(Console.ReadLine()!);
var n = j - 1;
var ans = 0;
if (n >= 3) ans = n * (n - 1) * (n - 2) / 6;
Console.WriteLine(ans);
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int j;
if (!(cin >> j)) return 0;
int n = j - 1;
int ans = 0;
if (n >= 3) ans = n * (n - 1) * (n - 2) / 6;
cout << ans << "\n";
return 0;
}