UVA - 12294 RPG battles (dp)

本文介绍了一种在典型角色扮演游戏(RPG)中优化战斗策略的方法。玩家需要通过合理使用两种药水来提升自身实力,以尽可能快地赢得所有战斗。文章详细解释了如何通过动态规划算法来解决这一问题。
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 (1 ≤ n ≤ 1000,
1 ≤ p ≤ 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 ≤ p1 < p2 ≤ 100, 1 ≤ t2 < t1 ≤ 100, 0 ≤ w1, w2 ≤ 10). 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 一个是战斗次数,一个是初始力量值 (我们必须按照顺序完成战斗),我们有两种药水 ,1 . 力量+1   2 . 力量*2 , 我们完成战斗花费时间  ,要是力量在p1下,不能完成战斗 ,大于或等于p2 ,时间为t2 ,在p1 -p2 之间 ,力量和时间成线性关系  如 力量55  p1 50  p2  75  t1  40  t2  15 ,时间为35  

显然我们有+1就把+1喝掉这是最优的 ,然后我们可以选择是否喝*2 ,因为 早喝和晚喝增长力量可能不同 

那么  dp[i][j][k]  i代表第几场比赛结束 ,j 代表当前力量 ,k 代表剩余的*2药水数  ,dp存的值为最小时间 

比如 dp[1][10][1]=1.0 代表第1场比赛结束后,你有10点力量,1瓶药水 ,到这种情况的最小时间为1.0

因为 p1,p2范围最大为100 ,所以dp范围到100就好 ,有再多力量也只需要100 ,那么 药水最多7瓶肯定力量会超过100

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
int n,p;
double p1,p2,t1,t2;
double dp[1100][200][10];
int w1[1100];
int w2[1100];
bool v[1110][200][10];//这种情况是否出现过
double pp(double x,double y)//输出花费时间
{
    if(x>=p2) return t2;
    return t1-(x-p1)*y;
}
int main()
{
  while(~scanf("%d%d",&n,&p)&&n+p)
  {
      memset(v,0,sizeof(v));
      memset(dp,0,sizeof(dp));
      v[0][p][0]=1;
        for(int i=1;i<=n;i++)
        {
        scanf("%lf%lf%lf%lf%d%d",&p1,&p2,&t1,&t2,&w1[i],&w2[i]);
        double pos=(t1-t2)/(p2-p1);
        for(int j=p1;j<=100;j++)//最大力量100
        {
            for(int k=0;k<=7;k++)//最多有7瓶药水
                if(v[i-1][j][k]) 
                {
                    int e=min(7,k+w2[i-1]);//我们最多只需要7瓶药
                    int e1=min(j+w1[i-1],100);//最大力量只需要100
                    for(int kk=e;kk>=0;kk--,e1*=2)
                    {
                        if(e1>=100) //超过100按100计算,而且直接break ,因为你不需要在嗑药了,力量达上限
                        {
                            if(v[i][100][kk])
                            {
                                dp[i][100][kk]=min(dp[i][100][kk],dp[i-1][j][k]+pp(100.0,pos));
                            }
                            else
                            {
                                v[i][100][kk]=1;
                                dp[i][100][kk]=dp[i-1][j][k]+pp(100.0,pos);
                            }
                            break;

                        }
                        if(!v[i][e1][kk])
                        {
                            dp[i][e1][kk]=dp[i-1][j][k]+pp(e1*1.0,pos);
                            v[i][e1][kk]=1;
                        }
                        else
                            dp[i][e1][kk]=min(dp[i][e1][kk],dp[i-1][j][k]+pp(e1*1.0,pos));
                    }
                }
        }

        }
        double ans=inf;
        for(int i=1;i<=100;i++)
            for(int j=0;j<10;j++)
              if(v[n][i][j])
              ans=min(ans,dp[n][i][j]);
        if(ans==inf)
            printf("Impossible\n");
        else
            printf("%.2lf\n",ans);
  }
}

1)普通用户端(全平台) 音乐播放核心体验: 个性化首页:基于 “听歌历史 + 收藏偏好” 展示 “推荐歌单(每日 30 首)、新歌速递、相似曲风推荐”,支持按 “场景(通勤 / 学习 / 运动)” 切换推荐维度。 播放页功能:支持 “无损音质切换、倍速播放(0.5x-2.0x)、定时关闭、歌词逐句滚动”,提供 “沉浸式全屏模式”(隐藏冗余控件,突出歌词与专辑封面)。 多端同步:自动同步 “播放进度、收藏列表、歌单” 至所有登录设备(如手机暂停后,电脑端打开可继续播放)。 音乐发现与管理: 智能搜索:支持 “歌曲名 / 歌手 / 歌词片段” 搜索,提供 “模糊匹配(如输入‘晴天’联想‘周杰伦 - 晴天’)、热门搜索词推荐”,结果按 “热度 / 匹配度” 排序。 歌单管理:创建 “公开 / 私有 / 加密” 歌单,支持 “批量添加歌曲、拖拽排序、一键分享到社交平台”,系统自动生成 “歌单封面(基于歌曲风格配色)”。 音乐分类浏览:按 “曲风(流行 / 摇滚 / 古典)、语言(国语 / 英语 / 日语)、年代(80 后经典 / 2023 新歌)” 分层浏览,每个分类页展示 “TOP50 榜单”。 社交互动功能: 动态广场:查看 “关注的用户 / 音乐人发布的动态(如‘分享新歌感受’)、好友正在听的歌曲”,支持 “点赞 / 评论 / 转发”,可直接点击动态中的歌曲播放。 听歌排行:个人页展示 “本周听歌 TOP10、累计听歌时长”,平台定期生成 “全球 / 好友榜”(如 “好友中你本周听歌时长排名第 3”)。 音乐圈:加入 “特定曲风圈子(如‘古典音乐爱好者’)”,参与 “话题讨论(如‘你心中最经典的钢琴曲’)、线上歌单共创”。 (2)音乐人端(创作者中心) 作品管理: 音乐上传:支持 “无损音频(FLAC/WAV)+ 歌词文件(LRC)+ 专辑封面” 上传,填写 “歌曲信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值