zoukankan      html  css  js  c++  java
  • zoj3433(贪心+优先队列)

    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" ).

    SuSu and QianYu

    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
    
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<queue>
     5 #include<vector>
     6 using namespace std;
     7 int n,t,m,b;
     8 int main()
     9 {
    10 //    freopen("C:/Users/lenovo/Desktop/input.txt","r",stdin);
    11 //    freopen("C:/Users/lenovo/Desktop/output.txt","w",stdout);
    12     scanf("%d",&t);
    13     while(t--)
    14     {
    15         vector<int>a[2005];
    16         scanf("%d",&m);
    17         for(int i=0;i<m;i++)
    18         {
    19             scanf("%d",&n);
    20             for(int j=0;j<n;j++)
    21             {
    22                 scanf("%d",&b);
    23                 a[i].push_back(b);
    24             }
    25         }
    26         int sum=0;
    27         int k=0;
    28         int amp;
    29         priority_queue<int>q;
    30         for(int i=0;i<m;i++)
    31         {
    32             scanf("%d",&amp);
    33             //q.push(amp);
    34             sum+=amp;
    35             for(int j=0;j<a[i].size();j++)
    36             {
    37                 sum-=a[i][j];
    38                 k++;
    39                 q.push(a[i][j]);
    40             }
    41             while(sum<0)
    42             {
    43                 sum+=q.top();
    44                 q.pop();
    45                 k--;
    46             }
    47 
    48         }
    49         printf("%d
    ",k);
    50     }
    51     return 0;
    52 }
  • 相关阅读:
    页面加载完没有其他操作的情况下直接获取音频时长为NAN问题
    关于mysql的一些操作
    阿里云服务器登录不上 提示:之前用于连接到 (公网ip) 的凭据无法工作(1核1G) 以及阿里云新版本安全组策略没有开启80端口导致网站只能ping通 访问不到的问题
    微信浏览器禁止页面下拉查看网址(不影响页面内部scroll)
    2018年11月17号第一次参加源创会记录
    使用了eclipse10年之后,我终于投向了IDEA
    spring/spring boot/spring cloud书籍推荐
    python数据库连接例子
    Spring Cloud Eureka配置文件例子与较为详细说明
    spring源代码下载并导入eclipse技巧
  • 原文地址:https://www.cnblogs.com/ZP-Better/p/4674327.html
Copyright © 2011-2022 走看看