UVA - 12294 RPG battles (dp)

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);
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
**数字乡村解决方案摘要** **国家战略与乡村振兴** 中国正实施国家大数据战略,以加快数字中国的建设,整合数据资源,保障数据安全,并推动产业升级。2023年中央一号文件强调了乡村振兴战略,旨在通过产业兴旺、生态宜居、乡风文明、治理有效和生活富裕五大方面,实现农业农村现代化。 **数字乡村建设的重要性** 数字乡村建设是乡村振兴战略的重要组成部分,通过整合资源数据,推动物联网和遥感技术在农业中的应用,促进农业现代化。它被视为促进乡村转型发展的新方向,是数字化在农业农村经济社会发展中的应用。 **关键要素与效益** 数字乡村建设的关键要素包括数据资源整合、产业促进、农业发展规模化和标准化,以及改善乡村生活服务体系。预期效益包括提升国家治理能力,实现政府决策科学化和社会治理精准化,同时推动公共服务高效化。 **体系架构与数据融合** 数字乡村的体系架构包括乡村生态、基层治理、慧治、慧享、慧融、慧美、慧智和慧图等多个方面,实现城乡、政企、农户各级平台及服务的融合。数据融合是核心,整合乡村人口、产值、环境监测等多方面数据,为乡村治理和产业发展提供支撑。 **多业务协同与智慧治理** 数字乡村通过多业务协同应用平台,实现乡村物联网的布局和触达,涵盖农业生产、农资厂商、消费者等环节。区块链技术在农产品质量溯源中的应用,确保了产品全过程可追溯。乡村智慧治理通过村务管理、财务管理等方面提升治理效能,实现绿色发展理念。综合服务体系通过“互联网+服务”模式,提供便民服务和乡村经济发展支持,推动乡村全面振兴。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值