• K.河北美食


    链接:https://ac.nowcoder.com/acm/contest/903/K

    题意:

    icebound最喜欢吃河北菜,于是他想要大厨做一桌河北菜宴请宾客。icebound购买了一些食材,并且制订了宴会的菜单。但是他并不知道这些食材是否足够,所以希望你写一个程序帮助他。
    icebound将会给出每种食材的名称和数量,以及完整的菜单。菜单将包含每种菜品所需的食材及数量。菜单上的每道菜只需制作一次。

    思路:

    map记录,判断。

    代码:

    #include <bits/stdc++.h>
    using namespace std;
     
    typedef long long LL;
     
    map<string, LL> have, use;
    vector<string> order;
    vector<pair<string, LL> > res;
     
    int main()
    {
        int n, m, t;
        cin >> n >> m;
        string name;
        int sum;
        for (int i = 1;i <= n;i++)
        {
            cin >> name >> sum;
            order.push_back(name);
            have[name] += sum;
        }
        for (int i = 1;i <= m;i++)
        {
            cin >> t;
            while (t--)
            {
                cin >> name >> sum;
                use[name] += sum;
            }
        }
        bool flag = true;
        for (auto name:order)
        {
            if (use[name] > have[name])
            {
                flag = false;
                break;
            }
            res.push_back(make_pair(name, have[name]-use[name]));
        }
        if (!flag)
        {
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        for (auto it:res)
            if (it.second != 0)
                cout << it.first << ' ' << it.second << endl;
     
     
        return 0;
    }
    

      

  • 相关阅读:
    BZOJ 3522 Hotel
    BZOJ 1864 三色二叉树
    396595
    CodeForces
    CodeForces
    CodeForces
    E. 数字串
    算术基本定理总结
    Cyclic Nacklace 杭电3746
    Period
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10923656.html
Copyright © 2020-2023  润新知