티스토리 뷰

코딩테스트/백준

[BJ] 7568. 덩치

jhk828 2021. 2. 14. 03:17

[BJ] 7568. 덩치

www.acmicpc.net/problem/7568

 

7568번: 덩치

우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x, y)로 표시된다. 두 사람 A 와 B의 덩

www.acmicpc.net

import java.io.*;
import java.util.*;
// 210211

public class Main_BJ_7568_덩치 {
	
	static int N;
	static int[][] arr;
	static int[] rank;
	static boolean[] isSelected;
	static int[] numbers;
	
	static void permutation(int cnt, int L) {
		if (cnt==2) {
			
			int n1 = numbers[0];
			int n2 = numbers[1];
			
			if ((arr[n1][0] < arr[n2][0]) && (arr[n1][1] < arr[n2][1])) {
				rank[n1]++;
			}

			return;
		}
		
		if (L >= N) {
			return;
		}
		
		for(int i=0; i<N; i++) {
			if (isSelected[i]) continue;
			
			isSelected[i] = true;
			numbers[cnt] = i;
			permutation(cnt+1, L+1);

			isSelected[i] = false;
		}
	} 
	
	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		
		N = Integer.parseInt(br.readLine());
		
		arr = new int[N][2];
		rank = new int[N];
		Arrays.fill(rank, 1);
		isSelected = new boolean[N];
		numbers = new int[2];

		for(int i=0; i<N; i++) {
			st = new StringTokenizer(br.readLine(), " ");
			arr[i][0] = Integer.parseInt(st.nextToken()); // 몸무게
			arr[i][1] = Integer.parseInt(st.nextToken()); // 키
			
		}
		
		permutation(0, 0);
		
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<N; i++) {
			sb.append(rank[i] + " ");
		}
		
		System.out.println(sb.toString());
		
		br.close();
	} // main

}

'코딩테스트 > 백준' 카테고리의 다른 글

[BJ] 1436. 영화감독 숌  (0) 2021.02.14
[BJ] 1018. 체스판 다시 칠하기  (0) 2021.02.14
[BJ] 2231. 분해합  (0) 2021.02.14
[BJ] 2798. 블랙잭  (0) 2021.02.14
[BJ] 11729. 하노이 탑 이동 순서  (0) 2021.02.14
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/06   »
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
글 보관함