백준/단계별
백준 7568 C#) 덩치
alpacadabra
2022. 5. 25. 11:14
복잡하게 생각할수록 잘 안풀리는 문제다.
public static class PS
{
private static readonly int n;
private static (int weight, int height)[] list;
private static int[] rank;
static PS()
{
n = int.Parse(Console.ReadLine());
list = new (int, int)[n];
rank = new int[n];
}
public static void Main()
{
MakeList();
for (int i = 0; i < n; i++)
{
rank[i] = 1;
for (int j = 0; j < n; j++)
{
if (i == j)
continue;
if (list[i].weight < list[j].weight && list[i].height < list[j].height)
rank[i]++;
}
}
Console.Write(String.Join(' ', rank));
}
private static void MakeList()
{
string[] person;
for (int i = 0; i < n; i++)
{
person = Console.ReadLine().Split();
list[i] = (int.Parse(person[0]), int.Parse(person[1]));
}
}
}
1명과 n - 1명의 비교를 계속 반복한다. 등수는 1에서 시작한다.
등수에 영향을 주는 경우는 딱 하나다. 키와 몸무게가 비교 대상보다 모두 작을 때다.
그 외에는 영향을 주지 않는다. 그냥 저 경우만 체크해도 알아서 자기 등수를 찾아갈 것이다.
복잡하게 생각할 필요가 없는 문제였다.