Development Logs/Algorithms
[JAVA] 백준 7568번 : 덩치 (브루트포스)
유뱅유뱅뱅
2020. 10. 22. 18:35
반응형
문제
해결 방안
전체 경우의 수를 비교해보면 되는 간단한 문제이다. 완전탐색을 이용하여 peoples i번째의 키와 몸무게를 다른 j번째 키와 몸무게를 비교하면 된다.
코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// 덩치
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
int n = Integer.parseInt(str);
int[][] peoples = new int[n][2];
for(int i=0; i<n; i++) {
str = br.readLine();
peoples[i][0] = Integer.parseInt(str.split(" ")[0]);
peoples[i][1] = Integer.parseInt(str.split(" ")[1]);
}
// 입력끝 ====
int x1, y1;
int x2, y2;
int k;
for(int i=0; i<n; i++) {
x1 = peoples[i][0];
y1 = peoples[i][1];
k = 1;
for(int j=0; j<n; j++) {
if(i!=j) {
x2 = peoples[j][0];
y2 = peoples[j][1];
if(x1<x2 && y1<y2) {
k++;
}
}
}
System.out.print(k + " ");
}
}
}
반응형