HDU-2616
2024-08-22 19:31:59
Kill the monster
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1525 Accepted Submission(s): 1043Problem DescriptionThere 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.InputThe 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).OutputFor 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 Input3 10010 2045 895 403 10010 2045 905 403 10010 2045 845 40Sample Output32-1
题意:
有n个符咒,怪兽有m点血。每个符咒有两个属性:
1.伤害A;
2.在怪物血量低于M时造成2*A点伤害。
AC代码:
#include<bits/stdc++.h>
using namespace std; struct node{
int x,y;
}a[]; bool vis[];
int n,m,ans; void dfs(int m,int len){
if(len>=ans)
return;
if(m<=){
ans=min(ans,len);
return;
}
for(int i=;i<n;i++){
if(vis[i]==){
vis[i]=;
if(m<=a[i].y)
dfs(m-*a[i].x,len+);
else
dfs(m-a[i].x,len+);
vis[i]=;
}
}
} int main(){
while(cin>>n>>m){
for(int i=;i<n;i++){
cin>>a[i].x>>a[i].y;
}
memset(vis,,sizeof(vis));
ans=;
dfs(m,);
if(ans>){
cout<<-<<endl;
}
else{
cout<<ans<<endl;
}
}
return ;
}
最新文章
- 安装oracle
- MSSQ调优所需用的语句
- CentOS搭建NodeJS环境
- d3 scale 学习笔记
- [JS] JS模块化开发之RequireJS
- 别老扯什么Hadoop了,你的数据根本不够大
- css3设置边框属性
- [AngularJS] Best Practise - Resolve promises in router, defer controllers
- PDF数据防扩散系统方案
- Python日期操作
- [NOIP 2011]聪明的质监员
- Analyzing &#39;enq: HW - contention&#39; Wait Event (Doc ID 740075.1)
- HTML5_canvas_图片加载_双缓冲_跳帧闪烁问题
- Elastic Stack之Logstash进阶
- Error configuring application listener of class org.springframework.web.util
- go 通过http发送图片file内容
- SQL注入之Sqli-labs系列第五关和第六关(基于GET型的报错注入)
- centos7+hadoop完全分布式集群搭建
- Python: attrgetter()函数: 排序不支持原生比较的对象
- Grep console 设置
热门文章
- JavaScript 工厂模式和订阅模式
- DM8168 unrecoverable error: OMX_ErrorBadParameter (0x80001005) [resolved]
- STL之set具体解释(二)
- Intel&#174; RAID Software Users Guide
- UITableView 自带编辑删除 自己定义button
- 关于移动端文字无法垂直居中(或line-height不起作用)的问题的解决方案(网摘)
- 简化Android的startActivityForResult调用
- python2&;python3的区别
- Java类加载器( 死磕8)
- Hadoop实战-Flume之Hdfs Sink(十)