Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
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
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준-7568번/Java] 덩치 본문

Algorithm

[백준-7568번/Java] 덩치

1984 2022. 11. 21. 01:23

https://www.acmicpc.net/problem/7568

 

7568번: 덩치

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

www.acmicpc.net

* 브루트포스 (완전탐색)

* Comparator 를 사용해 보았다.

import java.io.*;
import java.util.*;

public class Main {

	private static class Size {
		int height;
		int weight;
		int order; // 입력 순서
		int rank;

		public Size(int height, int weight, int order) {
			this.height = height;
			this.weight = weight;
			this.order = order;
		}

		public int getHeight() {
			return this.height;
		}

		public int getWeight() {
			return this.weight;
		}

		public int getOrder() {
			return order;
		}

		public int getRank() {
			return rank;
		}

		public void setRank(int rank) {
			this.rank = rank;
		}

		@Override
		public String toString() {
			return "(" + getHeight() + ", " + getWeight() + " [" + getRank() + "])";
		}

	}

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		ArrayList<Size> arr = new ArrayList<Size>();

		for (int i = 0; i < N; i++) {
			arr.add(new Size(in.nextInt(), in.nextInt(), i));
		}

		Comparator<Size> sizeComparator = new Comparator<Size>() {
			@Override
			public int compare(Size o1, Size o2) {
				if ((o1.getHeight() > o2.getHeight() && o1.getWeight() > o2.getWeight())) {
					return -1;
				} else if ((o1.getHeight() < o2.getHeight() && o1.getWeight() < o2.getWeight())) {
					return 1;
				}
				return 0;
			}
		};

		for (Size size : arr) {
			int count = 1;
			for (Size size2 : arr) {
				if (sizeComparator.compare(size, size2) == 1) {
					count++;
				}
			}
			System.out.print(count + " ");
		}
	}

}

'Algorithm' 카테고리의 다른 글

[백준-5635번/Java] 생일  (0) 2022.11.21
[백준-1436번/Java] 영화감독 숌  (0) 2022.11.21
[백준-2231번/Java] 분해합  (0) 2022.11.20
[백준-10815번/Java] 숫자 카드  (0) 2022.11.20
[백준-1966번/Java] 프린터 큐  (0) 2022.11.19
Comments