zoukankan      html  css  js  c++  java
  • hdu Dota all stars

    Dota all stars

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 81    Accepted Submission(s): 35
     
    Problem Description
    Dota as a popular computer game has serval years. Lots of Dota fans know that the equipment in the game is very important. To get a excellent equipment may be pass many processes.  Look the picture, you may see that in order to get the finally one must get the other two first. But this two may be can not get directly.                       
    Now give the primary equipments which you can buy it by money directly in the shop. And the numbers of equipments you already have. You also know all the formulas how to get a new better equipment by primary equipments. Last give the numbers of equipments you want, tell us how much extra money you need.
     
    Input
    The input contains multiple test cases. First part a integer n1 expressing the numbers of primary equipments you can buy in the shop. Next n1 lines, each line form as S V,S is the name of equipment and V meaning you should cost V money to buy one equipments S. Second part a integer n2 expressing the numbers of kinds equipments you have. Next n2 lines, each line form as S,M, meaning the numbers of equipment S you have is M. Third part a integer n3 expressing the numbers of formulas. Next n3 lines, each line have a character '=', The left is the equipments you should use to get the right equipment. For example A + B + C = D, In order to get a D, you must use A,B,C,D.each one. Last part a integer n4, expressing n4 kinds of equipments you need. Than n4 lines, each line form as S,M. Meaning the numbers of equipment S you need is M.
    You may sure the total kinds of equipment will not larger than 100. And the lengths of equipment name will less than 50.(a chinese words made up of two character )
     
    Output
    Output the extra money you need to achieve goal.
     
    Sample Input
    4
    欢欣之刃 100
    敏捷之靴 20
    半兽人之斧 100
    力量腰带 50
    2
    散华 1
    力量腰带 2
    3
    欢欣之刃 + 敏捷之靴 = 散华
    半兽人之斧 + 力量腰带 = 夜叉
    散华 + 夜叉 = 散夜对剑
    1
    散夜对剑 2
    
    5
    鹰角弓 3200
    短棍 1100
    攻击之爪 950
    阔剑 1200
    恶魔刀锋 2600
    0
    3
    鹰角弓 + 短棍 = 蝴蝶
    攻击之爪 + 阔剑 = 水晶剑
    水晶剑 + 恶魔刀锋 = 大炮
    2
    蝴蝶 1
    大炮 1
     
    Sample Output
    320
    9050
     
    Author
    yifenfei
     
    Source
    2009浙江大学计算机研考复试(机试部分)——全真模拟
     
    Recommend
    lcy

    分析:很典型的dfs,本题难点在于用STL中的map来建立字符串与整数的对应。

    #include<cstdio>
    #include<string>
    #include<iostream>
    #include<cstring>
    #include<map>
    using namespace std;
    char s[55];
    int hc[110][110];
    int k[110];
    int have[110];
    int price[110];
    int temp[110];
    int money, flag,mo;
    void dfs(int want)
    {
       // printf("want=%d\n",want);
        if(have[want])
        {
        //    printf("have want=%d",want);
            flag=0;
            have[want]--;
        }
        else if(k[want])
        {
            int i;
            for(i=1;i<=k[want];++i)
                dfs(hc[want][i]);
        }
        else
        {
            money+=price[want];
        } 
    }
    int main() {
        int n1, n2, n3, n4, i;
        int order, cnt,t,n;
        while (scanf("%d", &n1) != EOF) {
            map<string, int> mymap;
            memset(k, 0, sizeof (k));
            money = order = 0;
            memset(have, 0, sizeof (have));
            memset(k, 0, sizeof (k));
            for (i = 1; i <= n1; ++i) {
                scanf("%s", s);
                if (!mymap[s])
                    mymap[s] = ++order;
                scanf("%d", &price[mymap[s]]);
            }
            scanf("%d", &n2);
            for (i = 1; i <= n2; ++i) {
                scanf("%s", s);
                if (!mymap[s])
                    mymap[s] = ++order;
                scanf("%d", &have[mymap[s]]);
            }
            scanf("%d", &n3);
            for (i = 1; i <= n3; ++i) {
                cnt = 0;
                while (1) {
                    scanf("%s", s);
                    if (!mymap[s])
                        mymap[s] = ++order;
                    temp[++cnt] = mymap[s];
                    scanf("%s", s);
                    if (s[0] == '=')
                        break;
                }
                scanf("%s", s);
                if (!mymap[s])
                    mymap[s] = ++order;
                k[mymap[s]] = cnt;
                while (cnt) {
                    hc[mymap[s]][cnt] = temp[cnt];
                    cnt--;
                }
            }
            scanf("%d", &n4);
            for (i = 1; i <= n4; ++i) {
                scanf("%s", s);
                if (!mymap[s])
                    mymap[s] = ++order;
                t=mymap[s];
                scanf("%d", &n);
                while(n--)
                {
                    flag=1;
                    mo=money;
                    dfs(t);
               //     printf("n=%d money=%d\n",n,money);
                    if(flag)
                    {
                        money+=n*(money-mo);
                        break;
                    }
                }
                
            }
            printf("%d\n",money);
            
        }
        return 0;
    }
  • 相关阅读:
    netty 解决TCP粘包与拆包问题(二)
    Socket通讯-Netty框架实现Java通讯
    SpringBoot集成Swagger,Postman,newman,jenkins自动化测试.
    Java Console/控制台 打印表格
    mysql控制台的一些技巧,显示,输入换行,语法正则等
    “妈妈,我不想学了”,你的回答改变孩子一生(怅然若失,说了一句话:“为什么当初没有人逼我?”。我不愿意学,你就不让我学啦!那时候我还小,我还不懂事,难道你也不懂事吗。要做成一件事,就必须有延迟满足的能力)
    “太子”显然沉稳不足,急于把大权抓在自己手里,做的第一件事居然是想尽一切办法铲除父亲在公司的亲信(我很久以来的疑惑,看了这段才明白,相比之下,经过玄武门之变的李世民仍然忍了裴寂三年时间是何等的聪明和了不起)
    如何分析和提高大型项目(C/C++)的编译速度?(VS2015特有的:/LTCG:incremental选项)
    Duilib学习之基础(一个SDK程序)
    使用 QWorker 做为计划任务引擎
  • 原文地址:https://www.cnblogs.com/baidongtan/p/2666260.html
Copyright © 2011-2022 走看看