zoukankan      html  css  js  c++  java
  • FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)

    FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)

    Time Limit: 1000MS   Memory Limit: 257792K

    【Description】

    【题目描述】

    Fat Brother is a Great warrior(战士) and he has a powerful weapons named “Gorehowl”. Firstly it can cause 7 damage points to the other side, but it will decrease 1 damage points after one attack.

     

    One day, Fat Brother meet N monsters, but he only take his “Gorehowl”.

     

    Each monster has health points. When Fat Brother attacked a monster, the monster’s health points will decrease damage points of “Gorehowl”. If a monster’s health points less than or equal to zero, it die. Fat Brother must kill all monsters or he can’t get away from here. If he can kill all monster, he want to know least of times he should attack. If he can’t, he will choose go die.

    胖哥是一位信仰战,并且他拥有把名叫“血吼”的强力武器。一开始可以对一个目标造成7点伤害,然后每次攻击后减少1点攻击力。

     

    一天,胖哥偶遇N只随从,但是他只带了“血吼”。

     

    每只随从都有一定的生命值。当胖哥攻击一只随从后,这只随从的生命值会被减去“血吼”的攻击力。如果一只随从的生命值小等于0,即死亡。胖哥解决所有随从否则无法脱身。如果胖哥能够清场,他想知道最少的攻击次数。如果不行,他选择死亡。

    【Input】

    【输入】

    There are multiple test cases. The first line of input contains an integer T (T <= 50) indicating the number of test cases. For each test case:

     

    The first line contains one integer N (1 <= N <= 100000) means number of monsters.

     

    The next line contains N number Hi (1<= Hi <= 10) means monster’s health points.

    多组测试用例。

    第一行是一个整数T(T <= 50)表示测试用例的数量。对于每个测试用例:

     

    第一行是一个整数N(1 <= N <= 100000)表示随从的数量。

     

    下一行有N个数Hi(1<= Hi <= 10),表示随从的生命值。

     

    【Output】

    【输出】

    If Fat Brother can kill all monsters, output a number means least of times Fat Brother should attack. Otherwise output “Fat Brother choose go die”

    如果胖哥能够消灭所有随从,输出他最少的攻击次数,否则输出“Fat Brother choose go die”

    【Sample Input - 输入样例】

    【Sample Output - 输出样例】

    3

    2

    12 6

    1

    28

    1

    29

    3

    7

    Fat Brother choose go die

    【Hint】

    【提示】

    First

    case, First attack first monster and it’s health points decrease to 5. Second attack second monster and it’s health points decrease to 0, it will die. Third attack first monster and it’s health points decrease to 0, it will die. All monster die!

     

     

    Second

    case, attack first monster 7 times, and sum of damage points is 7 + 6 + 5 + 4 + 3 + 2 + 1 = 28, kill all monster.

     

     

    Third

    case, Fat Brother can’t kill first monster, so he will choose go die.

     

     

    The test sample just explain problem, you can think the really data is accord with the title's description

    第一个样例,

    第一次攻击第一只随从使其生命值归5。第二次攻击第二只随从使其生命值归0,把它消灭。第三次攻击第一只随从使其生命值归0,把它消灭。所有随从阵亡。

     

    第二个样例,

    攻击第一只随从7次,攻击力的和为7 + 6 + 5 + 4 + 3 + 2 + 1 = 28,所有随从阵亡。

     

    第三个样例,

    胖哥无法解决第一只随从,因此他选择死亡。

     

    测试用例仅供说明,你可认为实际数据都符合题目描述。

    【题解】

    实际需要处理的数据量不大,暴力搜索应该没问题,不过出于看(qiang)得(po)爽(zheng),就用贪心了。

    一共只能攻击7次,分别是 1 2 3 4 5 6 7

    那么先在读取的时候剪个枝,N > 7或 Hid的和 > 28,直接选择死亡。

    然后我们把血吼每次的攻击力离散化,变成你每次都能造成1~7点伤害,但是造成的伤害不能重复。

    为了尽快砍死随从,可用攻击力 = 当前随从生命值 的情况最优先使用。

    其次若没有恰好相等的情况,为了减少浪费,则用剩余的最高可用攻击力砍生命值最高的随从。

    【代码 C++】

     1 #include<cstdio>
     2 #include <cstring>
     3 #include <queue>
     4 std::priority_queue<int, std::vector<int> > data, wait;
     5 bool us[8];
     6 int n;
     7 bool read(){
     8     scanf("%d", &n);
     9     int i, j, s;
    10     if (n > 7){
    11         for (i = 0; i < n; ++i) scanf("%d", &j);
    12         return 0;
    13     }
    14     while (!data.empty()) data.pop();
    15     memset(us, 0, sizeof(us));
    16     for (i = s = 0; i < n; ++i){
    17         scanf("%d", &j); s += j;
    18         if (j <= 7 && !us[j]) ++us[j];
    19         else data.push(j);
    20     }
    21     if (s>28) return 0;
    22     while (!wait.empty()) wait.pop();
    23     for (i = 1; i <= 7; ++i) if (!us[i]) wait.push(i);
    24     return 1;
    25 }
    26 int main(){
    27     int t, i, j, d, w;
    28     while (~scanf("%d", &t)){
    29         while (t--){
    30             if (read()){
    31                 while (!wait.empty() && !data.empty()){
    32                     w = wait.top(); wait.pop(); ++us[w];
    33                     d = data.top(); data.pop(); d -= w;
    34                     if (d > 0){
    35                         if (d <= 7 && !us[d]) ++us[d];
    36                         else data.push(d);
    37                     }
    38                     while (!wait.empty() && us[wait.top()]) wait.pop();
    39                 }
    40                 if (data.empty()){
    41                     for (i = j = 0; i <= 7; ++i) if (us[i]) ++j;
    42                     printf("%d
    ", j);
    43                 }
    44                 else puts("Fat Brother choose go die");
    45             }
    46             else puts("Fat Brother choose go die");
    47         }
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    Git 生命周期
    Git 配置环境
    JAVA克隆对象报错:The method clone() from the type Object is not visible
    C# 将字符串按要求分解成字符串数组
    servlet 标红的错误笔记
    TIBCO Jaspersoft Studio 报表软件使用教程
    错误笔记4
    ^按位运算详解
    表现层状态转换
    servlet 读取文件
  • 原文地址:https://www.cnblogs.com/Simon-X/p/5407728.html
Copyright © 2011-2022 走看看