본문 바로가기

USACO/Bronze

백준 14455 Don't Be Last! (USACO January 2017 Bronze 1번)

문제 링크: https://www.acmicpc.net/problem/14455

 

14455번: Don't Be Last!

Farmer John owns 7 dairy cows: Bessie, Elsie, Daisy, Gertie, Annabelle, Maggie, and Henrietta. He milks them every day and keeps detailed records on the amount of milk provided by each cow during each milking session. Not surprisingly, Farmer John highly p

www.acmicpc.net

맵을 사용하여 소들의 이름과 우유양을 업데이트 하면서 입력받음. 

맵을 돌면서 최소 우유양 M을 찾고, 맵안에 key의 갯수가 7개보다 적으면 M을 0이라고 둠.

맵을 다시 돌면서 M을 제외한 두번째 최소값인 MM을 찾음.

마지막으로 맵을 돌면서 우유양의 MM인 소들의 수를 세고, 그 수가 1이면 이름을 출력하고, 1이 아니면 "Tie"를 출력함.

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
#include <bits/stdc++.h>
using namespace std;
 
int N;
map<stringint> c2m;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> N;
    while(N--) {
        string name;
        int milk;
        cin >> name >> milk;
        c2m[name] += milk;
    }
 
    int M = 1e9;
    for(auto it = c2m.begin(); it != c2m.end(); it++)
        M = min(M, it->second);
    if(c2m.size() < 7) M = 0;
 
    int MM = 1e9;
    for(auto it = c2m.begin(); it != c2m.end(); it++) {
        if(it->second == M) continue;
        MM = min(MM, it->second);
    }
 
    int cnt = 0;
    string ans = "";
    for(auto it = c2m.begin(); it != c2m.end(); it++) {
        if(it->second == MM) {
            cnt++;
            ans = it->first;
        }
    }
 
    if(cnt == 1cout << ans << '\n';
    else cout << "Tie" << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter