Completion over Perfection

백준 13866 - 팀 나누기 (JAVA) 본문

앨고리듬 알고리즘

백준 13866 - 팀 나누기 (JAVA)

난차차 2020. 11. 7. 12:17
반응형

백준 13866 - 팀 나누기 (JAVA)

 

 

 

www.acmicpc.net/problem/13866

 

13866번: 팀 나누기

입력은 네 개의 정수 A, B, C 및 D가 포함된 한 줄로 구성되며 4명의 스킬 레벨이 주어진다. (0 ≤ A ≤ B ≤ C ≤ D ≤ 104)

www.acmicpc.net

 

엄청 간단해 보이지만 은근 생각해야되는 문제였다. 

포인트는 Math.min 함수를 쓰는 것!

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.*;
 
 
public class Making_team {
    
    static int a,b,c,d;
    static int team[];
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        
        team = new int [4];
            
        team[0= a;
        team[1= b;
        team[2= c;
        team[3= d;
        
        int sum = a+b+c+d; //41
        int min = 10000;
        for (int i=0; i<4; i++){
            for(int j=i+1; j<4; j++){
                int gap = 0;
                int temp_team1 = 0;
                int temp_team2 = 0;
                temp_team1 = team[i] + team[j]; //11
                temp_team2 = sum - temp_team1; //30 
                if (temp_team1<temp_team2) {
                    gap = temp_team2 - temp_team1; //19
                }else {
                    gap = temp_team1 - temp_team2; 
                }
                min = Math.min(min, gap);
            }
        }
        System.out.print(min);
    }
}
cs

 

반응형
Comments