1487E - Cheap Dinner 2000

题目来源

https://codeforces.ml/problemset/problem/1487/E

题意分析

  给定四种菜以及他们的数量,在分别给出m1个第一道菜和第二道菜不能搭配的条件,m2个第二道菜和第三道菜不能搭配的条件,m3个第三道菜和第四道菜不能搭配的条件,问找一种搭配使得所有菜都能拿一种,求最小花费。

思路分析

  [待补充]

code

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn = 2e5 + 7;
pair <int, int> a[maxn], b[maxn], c[maxn], d[maxn];
vector <int> v[maxn];

int main(){
    int n1, n2, n3, n4; scanf("%d%d%d%d", &n1, &n2, &n3, &n4);
    for (int i=1; i<=n1; i++) scanf("%d", &a[i].first), a[i].second = i;
    for (int i=1; i<=n2; i++) scanf("%d", &b[i].first), b[i].second = i;
    for (int i=1; i<=n3; i++) scanf("%d", &c[i].first), c[i].second = i;
    for (int i=1; i<=n4; i++) scanf("%d", &d[i].first), d[i].second = i;
    int m1, m2, m3;
    scanf("%d", &m1);
    sort(a+1, a+1+n1);
    for (int i=1; i<=m1; i++){
        int _u, _v; scanf("%d%d", &_u, &_v);
        v[_v].push_back(_u);
    }
    for (int i=1; i<=n2; i++){
        bool flag = false;
        for (int j=1; j<=n1; j++){
            if (find(v[i].begin(), v[i].end(), a[j].second) == v[i].end()){
                b[i].first = min(b[i].first + a[j].first, INF);
                flag = true; break;
            }
        }
        if (!flag) b[i].first = INF;
    }
    for (int i=1; i<=n2; i++) v[i].clear();

    sort(b+1, b+1+n2);
    scanf("%d", &m2);
    for (int i=1; i<=m2; i++){
        int _u, _v; scanf("%d%d", &_u, &_v);
        v[_v].push_back(_u);
    }
    for (int i=1; i<=n3; i++){
        bool flag = false;
        for (int j=1; j<=n2; j++){
            if (find(v[i].begin(), v[i].end(), b[j].second) == v[i].end()){
                c[i].first = min(c[i].first + b[j].first, INF);
                flag = true; break;
            }
        }
        if (!flag) c[i].first = INF;
    }
    for (int i=1; i<=n3; i++) v[i].clear();

    sort(c+1, c+1+n3);
    scanf("%d", &m3);
    for (int i=1; i<=m3; i++){
        int _u, _v; scanf("%d%d", &_u, &_v);
        v[_v].push_back(_u);
    }
    for (int i=1; i<=n4; i++){
        bool flag = false;
        for (int j=1; j<=n3; j++){
            if (find(v[i].begin(), v[i].end(), c[j].second) == v[i].end()){
                d[i].first = min(d[i].first + c[j].first, INF);
                flag = true; break;
            }
        }
        if (!flag) d[i].first = INF;
    }
    for (int i=1; i<=n4; i++) v[i].clear();
    int ans = INF;
    for (int i=1; i<=n4; i++) ans = min(ans, d[i].first);

//    for (int i=1; i<=n1; i++) cout << a[i].first << " ";
//    cout << endl;
//
//    for (int i=1; i<=n2; i++) cout << b[i].first << " ";
//    cout << endl;
//
//    for (int i=1; i<=n3; i++) cout << c[i].first << " ";
//    cout << endl;
//
//    for (int i=1; i<=n4; i++) cout << d[i].first << " ";
//    cout << endl;
    if (ans == INF) ans = -1;
    printf("%d\n", ans);
    return 0;
}

 

 

 

posted @ 2021-03-20 23:51  Rain_island  阅读(28)  评论(0编辑  收藏  举报
Title