CSU 1105
来源:互联网 发布:linux ant是否安装 编辑:程序博客网 时间:2024/05/20 10:22
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1105
1105: 打怪升级
Time Limit: 1 Sec Memory Limit: 64 Mb Submitted: 357 Solved: 104Description
对于多数RPG游戏来说,除了剧情就是打怪升级。本题的任务是用最短的时间取得所有战斗的胜利。这些战斗必须按照特定的顺序进行,每打赢一场,都可能会获得一些补药,用来提升力量。本题只有两种补药:“加1药”和“乘2药”,分别让你的力量值加1和乘以2。
战斗时间取决于你的力量。每场战斗可以用6个参数描述:p1, p2, t1, t2, w1, w2。如果你的力量小于p1,你将输掉战斗;如果你的力量大于p2,需要t2秒赢得战斗;如果力量位于p1和p2(包括p1和p2),战斗时间从t1线性递减到t2。比如p1=50,p2=75,t1=40,t2=15,你的力量为55,则战斗获胜需要35秒。注意,战斗时间可能不是整数。最后两个参数w1和w2分别表示战斗胜利后获得的“加1药”和“乘2药”的数量。注意,你不一定要立刻使用这些补药,可以在需要的时候再用,但不能在战斗中使用补药。
按顺序给出每场战斗的参数,输出赢得所有战斗所需的最短总时间。战斗必须按顺序进行,且不能跳过任何一场战斗。
Input
输入最多包含25组测试数据。每组数据第一行为两个整数n和p(1<=n<=1000, 1<=p<=100),即战斗的场数和你的初始力量值。以下n行每行6个整数p1, p2, t1, t2, w1, w2(1<=p1<p2<=100, 1<=t2<t1<=100, 0<=w1,w2<=10),按顺序给出各场战斗的参数。输入结束标志为n=p=0。
Output
对于每组数据,输出最短总时间(单位:秒),保留两位小数。如果无解,输出“Impossible”(不含引号)。
Sample Input
1 55 50 75 40 15 10 02 5550 75 40 15 10 050 75 40 15 10 03 11 2 2 1 0 51 2 2 1 1 01 100 100 1 0 01 74 15 35 23 0 01 12 3 2 1 0 00 0
Sample Output
35.0060.0041.0031.73Impossible
Hint
Source
湖南省第七届大学生计算机程序设计竞赛思路:可以知道,+1只要有就直接吃,*2可以等等吃。然后力量大于100以后是无敌的,所以不会有很多状态,看到很多博客都是dfs,我用的是bfs。
#include<cstdio>#include<iostream>#include<queue>#include<cstring>using namespace std;#define maxn 1005int p1[maxn], p2[maxn], t1[maxn], t2[maxn], w1[maxn], w2[maxn];int n,p;struct node{ int now; int p; double ti; int h2; node() {} node(int a,int b,double c,int e) { now=a; p=b; ti=c; h2=e; }};struct CMP{ bool operator()(node a,node b) { return a.ti>b.ti; }};void bfs(){ priority_queue<node ,vector<node >, CMP > q; while(!q.empty()) { q.pop(); } q.push(node(1,p,0,0)); int f=0; while(!q.empty()) { node k=q.top(); q.pop(); if(k.now==n+1) { f=1; printf("%.2f\n",k.ti); break; } int pos=k.now; if(k.p<p1[pos]) continue; node c; c.p=k.p+w1[pos]; c.now=k.now+1; c.h2=k.h2+w2[pos]; if(k.p>p2[pos]) { c.ti=k.ti+t2[pos]; } else { c.ti=k.ti+1.0*(1.0*p1[pos]*t2[pos]-1.0*p2[pos]*t1[pos]-(1.0*(t2[pos]-t1[pos])*k.p))/(1.0*p1[pos]-p2[pos]); } if(c.p<100) { q.push(c); int num=c.h2; for(int i=0; i<num; i++) { c.p=c.p*2; c.h2--; q.push(c); if(c.h2<=0) break; } } else { q.push(c); } } if(!f) { printf("Impossible\n"); }}int main(){ while(~scanf("%d%d",&n,&p)&&n+p) { for(int i=1; i<=n; i++) { scanf("%d%d%d%d%d%d",&p1[i],&p2[i],&t1[i],&t2[i],&w1[i],&w2[i]); } bfs(); } return 0;}
阅读全文
1 0
- CSU 1105
- CSU 1105
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- Codeforces Round #419 (Div. 2) (Codeforces 815B) D. Karen and Test 组合数学
- 历史盒子跳转页
- js操作cookie完成添加表单,存入cookie及读取cookie
- TF_IDF及其算法
- 【算法】矩阵 的 加、乘、转置
- CSU 1105
- springmvc数据验证
- Projects
- 什么是元类,怎么运用元类?
- 如何转载博客
- fabric.js的简单上手及基于fabric.js的canvas切图工具:1、基本使用及配置
- 在已有工程中实现微信图片压缩
- tomcat启动成功之后无法访问项目主页解决办法
- 一种基于javascript的索引建立