UVA - 12294 RPG battles

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.

Input

There will be at most 25 test cases. Each test begins with two integers
n and p ( 1n1000,
1p100),
the number of battles and your initial power. Each of the next
n lines contains 6 integers p1,
p2, t1,
t2, w1,
w2 ( 1p1 <
p2100,
1t2 <
t1100,
0w1,
w210). 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;
}

UVA - 12294 RPG battles

时间: 2024-11-05 16:05:28

UVA - 12294 RPG battles的相关文章

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B

[2016-02-19][UVA][129][Krypton Factor]

UVA - 129 Krypton Factor Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physica

[2016-02-03][UVA][514][Rails]

时间:2016-02-03 22:24:52 星期三 题目编号:UVA 514 题目大意:给定若干的火车(编号1-n),按1-n的顺序进入车站, 给出火车出站的顺序,问是否有可能存在 分析:    FIFO,用栈模拟一遍即可, 方法:    根据输入的顺序,从1-n开始,当前操作的为i 如果i是当前对应的编号,那么直接跳过(进入B) 如果不是,根据当前需求的编号,小于i,就从栈顶弹出一个元素, 看这个元素是否是需求的,是则继续.否则NO 1 2 3 4 5 6 7 8 9 10 11 12 13

uva 11584 Partitioning by Palindromes 线性dp

// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串的数目 // // f[i] = min(f[i],f[j-1] + 1(j到i是回文串)) // // 这道题还是挺简单的,继续练 #include <algorithm> #include <bitset> #include <cassert> #include <

uva 10003 Cutting Sticks 简单区间dp

// uva 10003 Cutting Sticks 区间dp // 经典的区间dp // dp(i,j)表示切割小木棍i-j所需要的最小花费 // 则状态转移为dp(i,j) = min{dp(i,k) + dp(k,j) + a[j]-a[i]) // 其中k>i && k<j // a[j] - a[i] 为第一刀切割的代价 // a[0] = 0,a[n+1] = L; // dp数组初始化的时候dp[i][i+1]的值为 0,这表示 // 每一段都已经是切割了的,不