반응형

문제 출처 :


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



알고리즘 분석 :


문제 해결에 필요한 사항

1. 정렬


- 해결한 문제 점수의 총합이 높은 참가자가 더 높은 순위를 가진다.

- 점수의 총합이 같은 경우, 제출 횟수가 적은 참가자가 더 높은 순위를 가진다.

- 점수의 총합과 제출 횟수가 같은 경우, 마지막으로 점수를 획득한 문제의 업로드 시간이 빠른 참가자가 더 높은 순위를 가진다.


이 문제에서 요구하는대로 정렬 함수를 만들어준다면 쉽게 문제 해결을 할 수 있다.







소스 코드 : 


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
47
48
49
50
51
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
 
using namespace std;
 
typedef pair<intint> pii;
 
vector<pair<pii, pii> > vc;
 
bool comp(const pair<pii, pii> &p, const pair<pii, pii> &q)
{
    int a = p.first.first;
    int b = p.first.second;
    int c = p.second.first;
 
    int aa = q.first.first;
    int bb = q.first.second;
    int cc = q.second.first;
 
    if (a == aa)
    {
        if (b == bb)
            return c < cc;
 
        return b < bb;
    }
    return a > aa;
}
int main()
{
    int n;
    scanf("%d"&n);
 
    for (int i = 1; i <= n; i++)
    {
        int a, b, c;
        scanf("%d %d %d"&a, &b, &c);
 
        vc.push_back({ {a,b},{c,i} });
    }
    sort(vc.begin(), vc.end(), comp);
 
    printf("%d", vc[0].second.second);
 
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형