zoukankan      html  css  js  c++  java
  • zoj-3433-Gu Jian Qi Tan

    /*
    Gu Jian Qi Tan
    
    --------------------------------------------------------------------------------
    
    Time Limit: 2 Seconds      Memory Limit: 65536 KB 
    
    --------------------------------------------------------------------------------
    
    Gu Jian Qi Tan is a very hot Chinese RPG in this summer vacation. SuSu is the most important role in the game. When SuSu first meet the ancient dragon QianYu, he will have a very difficult battle with QianYu. In order to resist QianYu's powerful attack, SuSu must make a special armor, which needs some precious materials ( We call it "Ice Heart" ). 
    
    
    Before this legend fight, SuSu must pass M dangerous labyrinth in order. In each labyrinth, there is a very powerful monster (We usually call it "BOSS") keeping watching the exit. So SuSu must defeat each BOSS if he wants to leave each labyrinth. When SuSu is fighting with a BOSS, he must attack its main body to kill it. however, some BOSS may have one or more special position of its body (such as wings, hands, weapons). SuSu can choose to attack these special positions and he will get one Ice Heart if he break the defence of one special position. Of course SuSu can choose not to attack special positions but just attack the BOSS's main body (in this situation, he can still kill the BOSS, but he cannot get Ice Heart). 
    
    The defence of all special positions are so strong that normal attack are not available. SuSu must use magic skill to attack it. Once he uses a magic skill, his mana point will decrease to 0. In order to recover mana point, he can eat a special food "Dan Gui Hua Gao" (a kind of cake). 
    
    In each labyrinth, SuSu can collect some cakes by killing small monsters. When he fights with a BOSS, his initial mana point will be 0. Different BOSS may have different amount of special positions, and the defence of different position may also be different ( that is, some positions may need just one magic attack but some may need to be attacked many times )
    Notice: cakes in previous labyrinth can be accumulated and brought to later labyrinth. 
    
    Can you tell how many Ice heart can SuSu get at most? 
    
    Input
    The first line of the input is a single integer T (T <= 20) indicating the number of test cases.
    In each case, fisrt there is a line containing one integer M ( M <= 1000) indicating the number of labyrinth.
    Then M lines follow. In the ith line, first there is an integer n (n <= 1000) indicating the amount of special positions this BOSS has. 
    Then followd by n integers, the ith integer ( no more than 20 ) indicating the amount of magic attacks SuSu must use to break the ith special position.
    Finally there is a line containing M integers, the ith integer ( no more than 20 ) indicating how many cakes SuSu can collect in the ith labyrinth.
    
    
    Output
    For each case, output one line, containing the maximum number of Ice Heart SuSu can get. 
    
    Sample Input
    1
    2
    1 10
    2 1 2
    10 0
    
    Sample Output
    2
    
    
    --------------------------------------------------------------------------------
    Author: HUANG, Qiao
    Contest: ZOJ Monthly, November 2010
    
    Submit    Status 
    题意:有m层迷宫,每层迷宫有一只怪物,怪物有ni个“特别的位置”,
    攻打每个位置需要cost[i]点魔,打完后可获得一个ice heart, 
    到达每层你就会有相应数量的魔,
    每层的魔可以累加使用,让你求出最多获得几个ice heart。
    
    解法:,尽可能地占下所有的ice heart,
    如果占下某个ice heart时将当前积累的Cake消耗成了负数,
    则放弃之前取得的一个消耗Cake最大的ice heart。
    
    
    
    贪心。对于一个ice heart,如果当前cake数大于或等于该ice heart的消耗,
    则直接取得,如果不,则用前面消耗的最大cake的与当前ice heart比较,
    当前ice heart消耗小些,则交换,赚一点cake,否则不换。用一个最大堆维护即可。
    
    */
    #include <iostream>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<cmath>
    #include<string.h>
    #include<stdio.h>
    #include<stdlib.h>
    using namespace std;
    #define maxn 2600
    
    int main()
    {
        int T,t,M,n,i,j,sum,k;
        scanf("%d",&T);
        while(T--)
        {
            vector<int>a[maxn];
            //开始把它定义成全局变量,没想到没有清空,报错
            //放在这里时每次循环会从新定义,可以不清空
            priority_queue<int> q;
            scanf("%d",&M);
            for(i=0; i<M; i++)
            {
                scanf("%d",&n);
                for(j=0; j<n; j++)
                {
                    scanf("%d",&t);
                    a[i].push_back(t);
                }
    
            }
            sum=0;
            k=0;
            for(i=0; i<M; i++)
            {
                scanf("%d",&t);
                sum+=t;
                for(j=0; j<a[i].size(); j++)
                {
                    sum-=a[i][j];
                    q.push(a[i][j]);
                    k++;
    
                }
                while(sum<0)
                {
                    sum+=q.top();
                    q.pop();
                    k--;
                }
    
            }
            /* for(i=0;i<M;i++)
            {
                for(j=0;j<a[i].size();j++)
                cout<<a[i][j]<<"  ";
                cout<<endl;
            }*/
            while(!q.empty())q.pop();
            printf("%d
    ",k);
        }
        return 0;
    }
  • 相关阅读:
    POJ 最小球覆盖 模拟退火
    POJ 1379 模拟退火
    PythonTip(2)
    PythonTip(1)
    LA 3353 最优巴士线路设计
    LA 4254 贪心
    判断分析
    因子分析——因子得分
    因子分析——应用
    因子分析——因子旋转
  • 原文地址:https://www.cnblogs.com/heqinghui/p/3226418.html
Copyright © 2011-2022 走看看