4.3.7 Kill the monster
来源:互联网 发布:aster遥感数据 编辑:程序博客网 时间:2024/05/18 11:25
Kill the monster
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 118 Accepted Submission(s): 86
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
#include<cstdio>#include<cstring>#include<stack>using namespace std;const int MAXN = 10;int a[MAXN], m[MAXN];int n, HP;struct node{int hp, t;bool vis[MAXN];};int dfs(){int mint = 1e6;stack<node> s;node cur, next;memset(cur.vis, 0, sizeof(cur.vis));cur.hp = HP;cur.t = 0;while(!s.empty()) s.pop();s.push(cur);while(!s.empty()){cur = s.top();s.pop();for(int i = 0; i < n; i++){next = cur;if(!next.vis[i]){if(next.hp <= m[i]){next.hp -= 2 * a[i];}else next.hp -= a[i];next.t++;next.vis[i] = 1;if(next.hp <= 0){if(mint > next.t) mint = next.t;continue;} s.push(next);}}}if(mint == 1e6)return -1;else return mint;}int main(){while(scanf("%d%d", &n, &HP) != EOF){for(int i = 0; i < n; i++){scanf("%d%d", &a[i], &m[i]);}int ans = dfs();printf("%d\n", ans);}return 1;}
0 0
- 4.3.7 Kill the monster
- hdu2616 kill the monster 4.3.8
- hdu_2616 Kill the monster
- HDU2616 Kill the monster
- - Kill the monster HDU2616
- hd2616 Kill the monster
- 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
- HDU-2616-Kill the monster
- Kill the monster(深搜)
- HDU 2616 Kill the monster
- 杭电 2616 Kill the monster
- android 后台视频录制【原创】
- hdu 4937 Lucky Number 2014 Multi-University Training Contest 7
- OC内存管理之release
- 第一篇博客!!!
- android硬编码h264-MediaCodec
- 4.3.7 Kill the monster
- oracle spfile 和 pfile
- 阻塞IO服务器模型之单线程服务器模型
- This is it——要学老队长,强行秀英语
- mysql oracle informix SqlServer 分页语句
- 2014-C第1周项目——初步体验分支结构和循环结构的程序设计 2 求两数正差值
- Android底层开发之字符绘制TextLayoutCache
- js学习笔记一
- 多校第七场