您的位置:首页 > 其它

F - 打怪升级

2017-08-22 20:24 501 查看
第一种药直接吃,第二种看情况,寻求最优,所以用dfs做,注意只要自己力量大于100了就横扫所有敌人,注意时间加减。

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<functional>
#include<set>
#include<map>
#include<cstdlib>
#include<vector>
#include<cmath>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
const int inf = 0x3f3f3f3f;
struct node {
int p1, p2, t1, t2, w1, w2;
}fight[1010];
int n, p, i;
double dfs(int i, int p, int d)
{
if (i > n-1)
return 0;
if (p*(1 << d) > 100)
return fight[i].t2 + dfs(i + 1, 200, 0);
double t = inf;
while (p < fight[i].p1&&d>0)
d--, p *= 2;
if (p < fight[i].p1)
return t;
double time;
while (d >= 0)
{
if(p>100)
return fight[i].t2 + dfs(i + 1, 200, 0);
if (p > fight[i].p2)
time = fight[i].t2;
else
time = ((double)(fight[i].t2 - fight[i].t1)*p + fight[i].t1*fight[i].p2 - fight[i].t2*fight[i].p1) / (double)(fight[i].p2 - fight[i].p1);
time += dfs(i + 1, p + fight[i].w1, d + fight[i].w2);
t = min(t, time);
d--;
p *= 2;
}
return t;
}
int main()
{
while (~scanf("%d %d", &n,&p) && n&&p)
{
for (i = 0; i < n; i++)
scanf("%d %d %d %d %d %d", &fight[i].p1, &fight[i].p2, &fight[i].t1, &fight[i].t2, &fight[i].w1, &fight[i].w2);
double time = dfs(0, p, 0);
if (time == inf)
printf("Impossible\n");
else
printf("%.2lf\n", time);
}
// system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  初学dfs