MVP-12294 RPG battles

Source: Internet
Author: User

Description


RPG battles

In your 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 lessP1, you will be defeated; if your power is greaterP2, you'll needT2 seconds to defeat all the enemies. If your power isP1 andP2 (random), the time needed for the battle decreases linearly fromT1T2. 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 andW2, 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 NAnd P(1 N1000,1 P100), the number of battles and your initial power. Each of the next NLines contains 6 Integers P1, P2, T1, T2, W1, W2 (1 P1 < P2100,1 T2 < T1100,0 W1, W210). The input is terminated by a test case N= P= 0, you shoshould 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, if your P is greater than P2, it takes only T2 seconds, we need to compare the linear time between t2 and T1. Then W1 represents the number of strength + 1 potion, W2 represents the number of power * 2 potion, so that you can eliminate the enemy in order, the shortest time: DP, set DP [I] [J] [k] to indicate the number of W2 flags of J's strength. Because we know that we can use more than 1, but we are not sure about the use of * 2, so we need to record that the maximum W2 value is no more than 7, and the maximum power is no more than 100. When the status is transferred, we enumerate if the current power of the ** 2 potion is not used, and then enumerate the ** 2 potion
#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;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.