UVA - 12294 RPG battles

来源:互联网 发布:韩顺平java和java ee 编辑:程序博客网 时间:2024/06/05 14:08

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 ofdouble 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 thanp1, you will be defeated; if your power is greater thanp2, you'll need t2 seconds to defeat all the enemies. If your power is betweenp1 and p2 (inclusive), the time needed for the battle decreases linearly fromt1 to t2. For example, ifp1 = 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 withn = 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 5550 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题意:给你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
原创粉丝点击