标签:des style blog http color 使用 os io
Description
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.
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
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; }
UVA - 12294 RPG battles,布布扣,bubuko.com
标签:des style blog http color 使用 os io
原文地址:http://blog.csdn.net/u011345136/article/details/38612583