[loj3527]地牢游戏
当英雄能力值$\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]地牢游戏的更多相关文章
- [LeetCode] Dungeon Game 地牢游戏
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...
- ✡ leetcode 174. Dungeon Game 地牢游戏 --------- java
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...
- [leetcode]174. Dungeon Game地牢游戏
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...
- [LeetCode] 174. Dungeon Game 地牢游戏
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...
- 虚拟现实外包公司—VR游戏你不知道的以及你该知道的WebVR
VR基础——原理其实很简单 我们地球人之所以能够看到立体的景物,是因为双眼可以各自独立看东西,也就是左眼只能看到左眼的景物,而右眼只能看到右眼的景物.因为人类左右两眼有间距,造成两眼的视角有些细微的差 ...
- CodeCombat编程游戏
一. 介绍 官方网站:http://cn.codecombat.com/ 项目地址:https://github.com/codecombat/codecombat CodeCombat 是一个通过玩 ...
- 2000G电脑大型单机游戏合集
激活码 游戏名称(ctrl+F查找) 下载链接005875 艾迪芬奇的记忆 游戏下载链接http://pan.baidu.com/s/1t2PYRAj546_1AcOB-khJZg554158 暗影: ...
- LeetCode(120):三角形最小路径和
Medium! 题目描述: 给定一个三角形,找出自顶向下的最小路径和.每一步只能移动到下一行中相邻的结点上. 例如,给定三角形: [ [2], [3,4], [6,5,7], [4,1,8,3] ] ...
- 2018-2019学年第一学期Java课设--魔塔
目录 Magic-Towers 一.团队名称.团队成员介绍.任务分配 团队名称:MoTa 团队成员介绍 任务分配 二.项目简介 三.项目采用技术 四.项目亮点 主界面显示主要信息功能 游戏动画 五.项 ...
随机推荐
- Python - poetry(1)包管理利器的入门介绍
Python 虚拟环境详解 https://www.cnblogs.com/poloyy/p/15266382.html poetry 官方介绍 github:https://github.com/p ...
- Serverless:这真的是未来吗?(一)
原文 | https://www.pulumi.com/blog/is_serverless_the_future_part_1/ 作者 | Lee Briggs & Piers Karsen ...
- 【nvidia jetson xavier】 Deepstream Yolov3示例模型运行
作者声明 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 原文链接:https://www.cnblogs.com/phoenixash/p/15 ...
- Winfrom窗体初始化和窗体Load方法前后
运行结果为 [窗体初始化之前!]>[窗体初始化!]>[窗体Load!]
- 用C++实现的数独解题程序 SudokuSolver 2.3 及实例分析
SudokuSolver 2.3 程序实现 用C++实现的数独解题程序 SudokuSolver 2.2 及实例分析 里新发现了一处可以改进 grp 算法的地方,本次版本实现了对应的改进 grp 算法 ...
- C#开发BIMFACE系列53 WinForm程序中使用CefSharp加载模型图纸1 简单应用
BIMFACE二次开发系列目录 [已更新最新开发文章,点击查看详细] 在我的博客<C#开发BIMFACE系列52 CS客户端集成BIMFACE应用的技术方案>中介绍了多种集成BIM ...
- 【NXOpen.UF扩展】修改表达式
public static class UFExpEx { /// <summary> /// 修改当前部件的表达式 /// </summary> /// <param ...
- Java---String和StringBuffer类
Java---String和StringBuffer类 Java String 类 字符串在Java中属于对象,Java提供String类来创建和操作字符串. 创建字符串 创建字符串常用的方法如下: ...
- HTTP标签
系统的http状态码知识,我是在<图解http里学习的>. 状态码的职责是告知从服务器端返回的请求结果. 分类如下: 2XX --> 成功 200 OK(一般情况) 204 No C ...
- (二)、Docker 快速入门
文档:https://docs.docker.com/install/linux/docker-ce/centos/ 中文文档:https://docs.docker-cn.com/engine/in ...