UVA - 12294 RPG battles

Description

Download as PDF


  RPG battles 

In many typical RPG games, you battle with bad guys, creatures, monsters or ghosts etc. all the time. After each battle, you may get magic potions that power you up, so you'll get stronger and stronger, and finally defeat the big boss. In this problem, we only consider two kinds of potion: stronger and double power. If you drink a bottle of stronger potion, your power increases by 1; if you drink a bottle of double power potion, your power doubles.

How long each battle lasts depends on how powerful you are. Each battle is described by six parameters: p1, p2, t1, t2, w1, w2. That means, if your power is less than p1, you will be defeated; if your power is greater than p2, you'll need t2 seconds to defeat all the enemies. If your power is between p1 and p2 (inclusive), the time needed for the battle decreases linearly from t1 to t2. For example, if p1 = 50, p2 = 75, t1 = 40, t2 = 15, and your power is 55, then the battle lasts for 35 seconds. Note that the time needed for battles may be non-integers. The last two parameters, w1 and w2, represent the number of bottles of stronger potion and double power potion you got after winning the battle. Note that you don't have to drink these potions immediately. You can drink them later if that'll decrease the total time. You cannot drink potions during a battle, so the time needed for battles is not affected by the potions.

Given the list of battles, your task is to find a strategy to win all the battles as quickly as possible. Note that you must enter the battles in order. You cannot redo or skip any battle.

Input 

There will be at most 25 test cases. Each test begins with two integers n and p ( 1$ \le$n$ \le$1000, 1$ \le$p$ \le$100), the number of battles and your initial power. Each of the next n lines contains 6 integers p1, p2, t1, t2, w1, w2 ( 1$ \le$p1 < p2$ \le$100, 1$ \le$t2 < t1$ \le$100, 0$ \le$w1, w2$ \le$10). The input is terminated by a test case with n = p = 0, you should not process it.

Output 

For each test case, print the shortest time (in seconds) to win all the battles, to two digits after the decimal point. If you cannot win all the battles, print `` Impossible" (without quotes).

Sample Input 

1 55
50 75 40 15 10 0
2 55
50 75 40 15 10 0
50 75 40 15 10 0
3 1
1 2 2 1 0 5
1 2 2 1 1 0
1 100 100 1 0 0
1 7
4 15 35 23 0 0
1 1
2 3 2 1 0 0
0 0

Sample Output 

35.00
60.00
41.00
31.73
Impossible

题意:给你n和p,你有n个敌人要打败,每个敌人有p1,p2,t1,t2,w1,w2,代表如果你的p大于p2的话,那么将只花费t2秒,在p1和p2之间的话,就需要在t2到t1的线性比时间
然后w1代表力量+1药水的数量,w2代表力量*2药水的数量,让你按顺序消灭敌人,求最短的时间
思路:DP,设dp[i][j][k]表示第i个敌人,此时j的力量的,w2药水的数量。因为我们知道一有+1的我们就用掉,但是*2的我们不确定使用,所以我们需要记录起来,w2的
最大值是不超过7,力量最大不超过100。在状态转移的时候,我们枚举的是如果没有使用*2药水当前的力量,再枚举*2药水
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double inf = 100000000.0;

double dp[1010][110][10];
int f[10];

void init() {
	f[0] = 1;
	for (int i = 1; i < 10; i++)
		f[i] = f[i-1] * 2;
}

double cal(int p1, int p2, int t1, int t2, int p) {
	if (p >= p2)	
		return t2;
	if (p < p1)
		return inf;
	return (double)t1 - 1.0*(t1-t2)/(p2-p1)*(p-p1);
}

int main() {
	int n, p, p1, p2, t1, t2, w1, w2;
	init();
	while (scanf("%d%d", &n, &p) != EOF && n+p) {
		scanf("%d%d%d%d%d%d", &p1, &p2, &t1, &t2, &w1, &w2);
		for (int i = 0; i <= 1005; i++)
			for (int j = 0; j <= 105; j++)
				for (int k = 0; k <= 9; k++)
					dp[i][j][k] = inf;
		int np = p + w1;
		dp[1][min(np, 100)][min(w2, 7)] = cal(p1, p2, t1, t2, p);

		for (int i = 2; i <= n; i++) {
			scanf("%d%d%d%d%d%d", &p1, &p2, &t1, &t2, &w1, &w2);
			for (int j = 1; j <= 100; j++)
				for (int k = 0; k <= 7; k++) 
					for (int l = 0; l <= k; l++) {
						int nu = j*f[l] + w1;
						int nk = k + w2 - l;
						double tmp = cal(p1, p2, t1, t2, j*f[l]);
						dp[i][min(nu, 100)][min(nk, 7)] = min(dp[i][min(nu, 100)][min(nk, 7)], dp[i-1][j][k]+tmp);
					}
		}	

		double ans = inf;
		for (int i = 1; i <= 100; i++)
			for (int j = 0; j <= 7; j++) 
				ans = min(ans, dp[n][i][j]);
		if (ans < inf)
			printf("%.2lf\n", ans);
		else printf("Impossible\n");
	} 	
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值