[UVA] 11308 - Bankrupt Baker@Morris' Blog|PChome Online 人新台
2013-06-29 21:50:57| 人819| 回0 | 上一篇 | 下一篇

[UVA] 11308 - Bankrupt Baker

0 收藏 0 0 站台

Problem B

BANKRUPT BAKER

Wolfgang Puck has an extensive collection of cake recipes. They are separated into different binders depending on the type of cake. Although Wolfgang has restaurant franchises all over the world, he is in a period of hard times and is struggling to afford ingredients for his cakes. What cakes can he create with his small budget?

Input

On the first line you are given t (1 ≤ t ≤ 100), the number of binders. Each binder begins with title, the name of the binder, then on the next line m n b (1 ≤ m, n ≤ 100, 1 ≤ b ≤ 106) where b is Wolfgang's budget in dollars. The next m lines are given as "ingredient c" (see sample input) where c (0 ≤ c ≤ 5000) is the price in dollars for one unit of ingredient.

Then follow n recipes. Each recipe begins with name on a line of its own, then on the very next line k (1 ≤ k ≤ 100). The following k lines are of the form "requirement x" (see sample input) where x is the number of units of the ingredient requirement used in the recipe name.

Output

For each binder, output the name of the binder in uppercase letters then on separate lines a list of recipes within Wolfgang's budget in increasing order of cost. If no such recipe exists, print "Too expensive!". If recipes have the same cost print them in lexicographical order. Print a blank line after each binder.

Sample Input

2 My Favourite Cheesecake 8 3 100 sugar 4 water 0 lemonjuice 3 creamcheese 20 vanilla 5 egg 5 cream 10 strawberry 5 Strawberry Whipped Cream 2 cream 5 strawberry 3 Scrumptious Caramel Topping 3 sugar 6 water 3 lemonjuice 1 Secret Cheesecake Base 5 creamcheese 3 sugar 5 vanilla 1 egg 6 cream 1 Million Dollar Cakes 3 1 999999 costlyflour 500 gold 4500 diamond 5000 Display Cake - Do Not Eat! 3 costlyflour 100 gold 100 diamond 100 

Output for the Sample Input

MY FAVOURITE CHEESECAKE Scrumptious Caramel Topping Strawberry Whipped Cream MILLION DOLLAR CAKES Too expensive! 

Sean McIntyre
Calgary Collegiate Programming Contest 2007

目描述:

一食的名, 面有一些蛋糕的食, 而手上有一些算, 同你每材料的,
接著告你每蛋糕分的材料量, 出可以做出的蛋糕, 出的候按照低到高,
相同的候按照蛋糕名的字典序出。

食的名一律成大。

#include <stdio.h>
#include <set>
#include <map>
#include <iostream>
using namespace std;
struct E {
    string name;
    int cost;
    bool operator<(const E & a) const {
        if(cost != a.cost)
            return cost < a.cost;
        return name.compare(a.name) < 0;
    }
};
int main() {
    int testcase;
    char name[105], foo[105], name2[105];
    scanf("%d", &testcase);
    while(getchar() != '\n');
    while(testcase--) {
        gets(name);
        int i;
        for(i = 0; name[i]; i++)
            if(name[i] >= 'a' && name[i] <= 'z')
                name[i] -= 32;
        puts(name);
        gets(foo);
        int n, m, cost, x, q;
        map<string, int> R;
        set<E> ret;
        E tmp;
        sscanf(foo, "%d %d %d", &n, &m, &cost);
        while(n--) {
            gets(foo);
            sscanf(foo, "%s %d", name, &x);
            R[name] = x;
        }
        while(m--) {
      &nbs;     gets(name);
            gets(foo);
            sscanf(foo, "%d", &q);
            int cc = 0;
            while(q--) {
                gets(foo);
                sscanf(foo, "%s %d", name2, &x);
                cc += R[name2]*x;
            }
            if(cc <= cost) {
                tmp.name = name;
                tmp.cost = cc;
                ret.insert(tmp);
            }
        }
        for(set<E>::iterator it = ret.begin();
            it != ret.end(); it++) {
            cout << it->name << endl;
        }
        if(ret.size() == 0)
            puts("Too expensive!");
        puts("");
    }
    return 0;
}

台: Morris
人(819) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA] 11459 - Snakes and Ladders
此分上一篇:[UVA][dp] 11157 - Dynamic Frog

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86