반응형
문제 출처 :
https://www.acmicpc.net/problem/14953
알고리즘 분석 :
문제 해결에 필요한 사항
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<int, int> 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 |
반응형
'Applied > 알고리즘 문제풀이' 카테고리의 다른 글
[14732번] 행사장 대여 (Small) (0) | 2018.01.15 |
---|---|
[2660번] 회장 뽑기 (0) | 2018.01.14 |
[14592번] 2017 아주대학교 프로그래밍 경시대회 (Small) (0) | 2018.01.14 |
[2916번] 자와 각도기 (0) | 2018.01.07 |
[2942번] 퍼거슨과 사과 (2) | 2018.01.05 |