Codeforces 1042 - B. Vitamins(模拟)

B. Vitamins

 

所有情况枚举一遍

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout<<"-----------------"<<endl;

typedef long long ll;
const int maxn = 1e5+10;
const int MAXN = 1e6+10;
const int INF = 1e8;
const int MOD = 1e9+7;
const int N = 1010;

int n;


int main(){
    while(scanf("%d", &n) != EOF){
        int v;
        string s;
        map<string, int> mp;
        mp["A"] = INF;
        mp["B"] = INF;
        mp["C"] = INF;
        mp["AB"] = INF;
        mp["AC"] = INF;
        mp["BC"] = INF;
        mp["ABC"] = INF;
        for(int i=0; i<n; i++){
            scanf("%d ", &v);
            cin >> s;
            sort(s.begin(), s.end());
            mp[s] = min(mp[s], v);
        }
        int ans = INF;
        ans = min(mp["A"] + mp["B"] + mp["C"], ans);
        ans = min(mp["A"] + mp["BC"], ans);
        ans = min(mp["B"] + mp["AC"], ans);
        ans = min(mp["C"] + mp["AB"], ans);
        ans = min(mp["AB"] + mp["AC"], ans);
        ans = min(mp["BC"] + mp["AC"], ans);
        ans = min(mp["AB"] + mp["BC"], ans);
        ans = min(mp["ABC"], ans);
        if(ans < 0 || ans >= INF) ans = -1;
        cout << ans << endl;
    }
    return 0;
}

 

    原文作者:B树
    原文地址: https://blog.csdn.net/l18339702017/article/details/82766911
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞