zoukankan      html  css  js  c++  java
  • HDU 2616 Kill the monster

    Kill the monster

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 718    Accepted Submission(s): 511


    Problem Description
    There is a mountain near yifenfei’s hometown. On the mountain lived a big monster. As a hero in hometown, yifenfei wants to kill it. 
    Now we know yifenfei have n spells, and the monster have m HP, when HP <= 0 meaning monster be killed. Yifenfei’s spells have different effect if used in different time. now tell you each spells’s effects , expressed (A ,M). A show the spell can cost A HP to monster in the common time. M show that when the monster’s HP <= M, using this spell can get double effect.
     
    Input
    The input contains multiple test cases.
    Each test case include, first two integers n, m (2<n<10, 1<m<10^7), express how many spells yifenfei has.
    Next n line , each line express one spell. (Ai, Mi).(0<Ai,Mi<=m).
     
    Output
    For each test case output one integer that how many spells yifenfei should use at least. If yifenfei can not kill the monster output -1.
     
    Sample Input
    3 100
    10 20
    45 89
    5 40
    3 100
    10 20
    45 90
    5 40
    3 100
    10 20
    45 84
    5 40
     
    Sample Output
    3
    2
    -1
     
    Author
    yifenfei
     
    Source
     
    Recommend
    yifenfei
     
    思路:简单DFS即可
     
    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int minn,sum,flag,n,m,ans;
    int PHchange;
    int hash[20];
    int biji;
    struct Node
    {
    int effect;
    int double_time;
    int PHchange;
    };
    Node map[20];
    void DFS(int now)
    {
    //printf("now is %d PHchange is %d sum is %d ",now,map[now].PHchange,sum);
    if(map[now].PHchange >= m)
    {
    ans = 1;
    if(sum < minn)
    minn = sum;
    return ;
    }
    for(int i = 1;i <= n;i ++)
    {
    if(hash[i] == 0)
    {
    sum ++;
    hash[i] = 1;
    if(m - map[now].PHchange <= map[i].double_time)
    map[i].PHchange = map[now].PHchange + map[i].effect * 2;
    else
    map[i].PHchange = map[now].PHchange + map[i].effect;
    DFS(i);
    sum --;
    hash[i] = 0;
    }
    }
    return ;
    }
    int main()
    {
    while(~scanf("%d%d",&n,&m))
    {
    for(int i = 0;i < 20;i ++)
    {
    map[i].effect = 0;
    map[i].double_time = 0;
    map[i].PHchange = 0;
    }
    memset(hash,0,sizeof(hash));
    for(int i = 1;i <= n;i ++)
    scanf("%d%d",&map[i].effect,&map[i].double_time);
    minn = 0;flag = 0;ans = 0;
    minn = 1000;
    for(int i = 1;i <= n;i ++)
    {
    sum = 1;
    biji = 0;
    hash[i] = 1;
    if(m <= map[i].double_time)
    map[i].PHchange = map[i].effect * 2;
    else
    map[i].PHchange = map[i].effect;
    DFS(i);
    hash[i] = 0;
    map[i].PHchange = 0;
    }
    if(ans == 0)
    printf("-1 ");
    else
    printf("%d ",minn);
    }
    }

  • 相关阅读:
    jQuery的实用技巧
    jQuery中的Ajax
    jQuery中的动画
    jQuery中的事件
    jQuery中的DOM操作
    详解jQuery的选择器
    微信小程序开发教程(九)视图层——.wxss详解
    微信小程序开发教程(八)视图层——.wxml详解
    14 组合查询
    13 创建高级联结
  • 原文地址:https://www.cnblogs.com/GODLIKEING/p/3333834.html
Copyright © 2011-2022 走看看