当英雄能力值$\ge 10^{7}$时,即能战胜所有敌人,简单预处理即可

若英雄能力值在$[2^{k},2^{k+1})$中,对敌人分类讨论:

1.若$s_{i}\le 2^{k}$,其必然会战胜这些敌人

2.若$s_{i}>2^{k}$,考虑快速找到其第一次战胜这些敌人的时刻,注意到战胜这些敌人后,其能力值必然$\ge 2^{k+1}$,那么至多发生$\log 10^{7}$次(之后其能力值即$\ge 10^{7}$)

下面,考虑用倍增来"快速找到其第一次战胜这些敌人的时刻",先假设对于所有第2类敌人其都会战败,在此情况下最小的差距,由此即可在$o(k)$的复杂度内找到该时刻

(假设初始能力值为0,且仍能战胜第1类敌人,也需要统计过程中能力值的增长)

由于空间问题,可以将范围修改为$[8^{k},8^{k+1})$,那么至多发生$8\log 10^{7}$次

时间复杂度为$o(n\log^{2}n)$,可以通过

 1 #include<bits/stdc++.h>
2 #include"dungeons.h"
3 using namespace std;
4 #define N 400005
5 #define L 24
6 #define LL 8
7 #define ll long long
8 int n,s[N],p[N],w[N],l[N],to[LL][N][L];
9 ll tot[N],sum[LL][N][L],delta[LL][N][L];
10 void init(int nn,vector<int>ss,vector<int>pp,vector<int>ww,vector<int>lll){
11 n=nn;
12 for(int i=0;i<n;i++){
13 s[i]=ss[i];
14 p[i]=pp[i];
15 w[i]=ww[i];
16 l[i]=lll[i];
17 }
18 for(int i=n-1;i>=0;i--)tot[i]=tot[w[i]]+s[i];
19 for(int i=0;i<LL;i++){
20 to[i][n][0]=n;
21 delta[i][n][0]=1e18;
22 for(int j=0;j<n;j++)
23 if (s[j]<=(1<<3*i)){
24 to[i][j][0]=w[j];
25 sum[i][j][0]=s[j];
26 delta[i][j][0]=1e18;
27 }
28 else{
29 to[i][j][0]=l[j];
30 sum[i][j][0]=p[j];
31 delta[i][j][0]=s[j];
32 }
33 for(int j=1;j<L;j++)
34 for(int k=0;k<=n;k++){
35 int x=to[i][k][j-1];
36 to[i][k][j]=to[i][x][j-1];
37 sum[i][k][j]=sum[i][k][j-1]+sum[i][x][j-1];
38 delta[i][k][j]=min(delta[i][k][j-1],delta[i][x][j-1]-sum[i][k][j-1]);
39 }
40 }
41 }
42 ll simulate(int x,int yy){
43 ll y=yy,time=0;
44 while ((x!=n)&&(y<(1<<L))){
45 int k;
46 for(int i=0;i<LL;i++)
47 if (((1<<3*i)<=y)&&(y<(1<<3*i+3))){
48 k=i;
49 break;
50 }
51 for(int i=L-1;i>=0;i--)
52 if (delta[k][x][i]>y){
53 y+=sum[k][x][i];
54 x=to[k][x][i];
55 }
56 if (x!=n){
57 y+=s[x];
58 x=w[x];
59 }
60 time++;
61 }
62 if (x!=n)y+=tot[x];
63 return y;
64 }
65 int main(){
66 freopen("1.in","r",stdin);
67 scanf("%*s");
68 int n,m,x,y;
69 vector<int>s,p,w,l;
70 scanf("%d%d",&n,&m);
71 for(int i=1;i<=n;i++){
72 scanf("%d",&x);
73 s.push_back(x);
74 }
75 for(int i=1;i<=n;i++){
76 scanf("%d",&x);
77 p.push_back(x);
78 }
79 for(int i=1;i<=n;i++){
80 scanf("%d",&x);
81 w.push_back(x);
82 }
83 for(int i=1;i<=n;i++){
84 scanf("%d",&x);
85 l.push_back(x);
86 }
87 init(n,s,p,w,l);
88 printf("TRUE\n");
89 for(int i=1;i<=m;i++){
90 scanf("%d%d",&x,&y);
91 simulate(x,y);
92 }
93 }

[loj3527]地牢游戏的更多相关文章

  1. [LeetCode] Dungeon Game 地牢游戏

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...

  2. ✡ leetcode 174. Dungeon Game 地牢游戏 --------- java

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...

  3. [leetcode]174. Dungeon Game地牢游戏

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...

  4. [LeetCode] 174. Dungeon Game 地牢游戏

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...

  5. 虚拟现实外包公司—VR游戏你不知道的以及你该知道的WebVR

    VR基础——原理其实很简单 我们地球人之所以能够看到立体的景物,是因为双眼可以各自独立看东西,也就是左眼只能看到左眼的景物,而右眼只能看到右眼的景物.因为人类左右两眼有间距,造成两眼的视角有些细微的差 ...

  6. CodeCombat编程游戏

    一. 介绍 官方网站:http://cn.codecombat.com/ 项目地址:https://github.com/codecombat/codecombat CodeCombat 是一个通过玩 ...

  7. 2000G电脑大型单机游戏合集

    激活码 游戏名称(ctrl+F查找) 下载链接005875 艾迪芬奇的记忆 游戏下载链接http://pan.baidu.com/s/1t2PYRAj546_1AcOB-khJZg554158 暗影: ...

  8. LeetCode(120):三角形最小路径和

    Medium! 题目描述: 给定一个三角形,找出自顶向下的最小路径和.每一步只能移动到下一行中相邻的结点上. 例如,给定三角形: [ [2], [3,4], [6,5,7], [4,1,8,3] ] ...

  9. 2018-2019学年第一学期Java课设--魔塔

    目录 Magic-Towers 一.团队名称.团队成员介绍.任务分配 团队名称:MoTa 团队成员介绍 任务分配 二.项目简介 三.项目采用技术 四.项目亮点 主界面显示主要信息功能 游戏动画 五.项 ...

随机推荐

  1. 从零入门 Serverless | SAE 的极致应用部署效率

    作者 | 文俊 阿里巴巴云原生团队 本文整理自<Serverless 技术公开课>,"Serverless"公众号后台回复"入门",即可获取系列文章 ...

  2. System.Drawing Linux Centos7 The type initializer for 'Gdip' threw an exception

    System.Drawing 在linux使用时提示异常 The type initializer for 'Gdip' threw an exception 解决方案: yum install au ...

  3. golang []byte和string的高性能转换

    golang []byte和string的高性能转换 在fasthttp的最佳实践中有这么一句话: Avoid conversion between []byte and string, since ...

  4. Java领域的表现层的三种技术--jsp、freemarker、velocity

    10月份忙碌的参加秋招并获得了5个成都.上海.广州等不同地区的工作offer,最终选择了广州,11月底来到公司实习,很快,就跟进了公司的项目了,原本以为可以和宣讲会时报的志愿一样--Java开发,但是 ...

  5. 2021.7.27--Benelux Algorithm Programming Contest 2020 补提

    I Jigsaw 题目内容: 链接:https://ac.nowcoder.com/acm/contest/18454/I 来源:牛客网 You have found an old jigsaw pu ...

  6. 耗时一个月,整理出这份Hadoop吐血宝典

    本文目录: 一.HDFS 二.MapReduce 三.Yarn 四.Hadoop3.x 新特性 五.Hadoop 大厂面试真题解析 Hadoop 涉及的知识点如下图所示,本文将逐一讲解: 本文档参考了 ...

  7. (课内)信安数基RSA-基础&&解密加速

    RSA基本实现 首先获得N比特的伪随机数:使用Random库中内容. randint(n,m) 表示生成一个在n和m之间的随机数, **表示乘幂. getPrime找素数,or 1运算是一种优化:如果 ...

  8. SharkCTF2021 BabyGame

    web类题. 访问题给页面,页面里没啥信息.抓包,发现: 访问它,发现是一个游戏. F12之后看调试器里的js代码,发现: console.log("balabalabala"); ...

  9. eclipse javase版安装插件开发web项目

    最近学习开发javaweb,但是安装的却是java se版的eclipse,但其无法新建web项目,即找不到Dynamic Web.所以需要下载相应插件.以下为操作过程. 1. 在联网的情况下,打开e ...

  10. 扩展spring data jpa的repository

    在我们编写代码的过程中,spring data jpa为我们的持久层提供的极大的方便,但有时spring data jpa提供的repository并不能完全满足我们开发的需求,因此就需要进行扩展.s ...