hd2616 Kill the monster
来源:互联网 发布:linux vim readonly 编辑:程序博客网 时间:2024/05/02 19:48
Kill the monster
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1241 Accepted Submission(s): 846
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.
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).
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 10010 2045 895 403 10010 2045 905 403 10010 2045 845 40
Sample Output
32-1题意:给定技能次数和怪物血量,在n次下打死怪物,规定:技能的AI为攻击伤害,MI为如果怪物的血量小于MI,此处的攻击伤害加倍。解题思路:深搜,cot 用于递归技能次数,m为怪物的血量,每次递归cot+1,m减去相应的血量,当m<=0时即为打死怪物,此时比较寻找最少技能次数。最终返回一个最小次数。#include <stdio.h>#include <stdlib.h>#include <string.h>int n,m,a[11][2],cot,visit[11],sum,min;int dfs(int cot,int m)//cot记录攻击次数,m为怪物血量{ int i; if(m <= 0)//当怪物血量为零时,寻找最小次数 { min = min > cot ? cot : min; } for(i=1;i<=n;i++)//遍历数组 { if(!visit[i])//是否用过 { visit[i] = 1;//标记 if(m <= a[i][1])//如果怪物血量小于技能的MI值,攻击伤害为2倍 dfs(cot+1,m-2*a[i][0]);//所以递归将血量减去2倍的攻击伤害 else dfs(cot+1,m-a[i][0]);//否则减去相应的血量即可 visit[i] = 0;//回溯 } }return min;}int main(){ int i; while(scanf("%d%d",&n,&m)!=EOF) { memset(visit,0,sizeof(visit)); for(i=1;i<=n;i++) { scanf("%d%d",&a[i][0],&a[i][1]); } min = 9999; if(dfs(0,m) == 9999)//如果min没有改变说明所有的技能都用完怪物的血量没有为0,即输出-1 printf("-1\n"); else printf("%d\n",min);//否则输出深搜得出的最小次数即可 } return 0;}
0 0
- hd2616 Kill the monster
- hdu_2616 Kill the monster
- HDU2616 Kill the monster
- - Kill the monster HDU2616
- Kill the monster
- hdu 2616 Kill the monster
- HDU 2616 Kill the monster
- HDU 2616 Kill the monster
- hdu(2616)Kill the monster
- HDU 2616 Kill the monster
- hdu 2616 Kill the monster
- ACdream P1072 Kill the monster
- 4.3.7 Kill the monster
- HDU-2616-Kill the monster
- Kill the monster(深搜)
- HDU 2616 Kill the monster
- hdu2616 kill the monster 4.3.8
- 杭电 2616 Kill the monster
- python(2)readlines()函数的注意问题
- 最简单的win32的窗口程序
- 解决使用Volley框架出现的乱码问题
- 6. ZigZag Conversion
- Ubuntu 安装 MongoDB
- hd2616 Kill the monster
- 自己写的下拉刷新的第三方库(适用于listview)
- RecyclerView基本使用
- spring和mybatis的整合配置(包括springmvc)
- NDK使用技巧、多线程调用注意、ndk中的工具使用
- AS的优化调整
- utilities(matlab)—— visualizes filters(可视化滤波器)
- 图解红黑树之2-3查找树
- Ubuntu 14.04 安装和配置Tomcat