[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 团队成员介绍 任务分配 二.项目简介 三.项目采用技术 四.项目亮点 主界面显示主要信息功能 游戏动画 五.项 ...
随机推荐
- mysql通过logstash同步数据到es
大小写问题很严重 input 1.statement:mysql的连接使用 jdk版本有强要求 2.jdbc_driver_library:jar包的版本有对应要求 3.jdbc_driver_cla ...
- ssh 批量免密登陆
SSH第一次连接远程主机 公钥交换原理 1.客户端发起链接请求2.服务端返回自己的公钥,以及一个会话ID(这一步客户端得到服务端公钥)3.客户端生成密钥对4.客户端用自己的公钥异或会话ID,计算出一个 ...
- 题解 2020.10.24 考试 T2 选数
题目传送门 题目大意 见题面. 思路 本来以为zcx.pxj变强了,后来发现是SPJ出问题了...考试的时候感觉有点人均啊...结果自己还是只想出来一半. 我们假设 \(f(x)=(\lfloor\f ...
- 洛谷5024 保卫王国 (动态dp)
qwq非正解. 但是能跑过. 1e5 log方还是很稳的啊 首先,考虑最普通的\(dp\) 令\(dp1[x][0]表示不选这个点,dp1[x][1]表示选这个点的最大最小花费\) 那么 \(dp1[ ...
- JVM详解(三)——运行时数据区
一.概述 1.介绍 类比一下:红框就好比内存的运行时数据区,在各自不同的位置放了不同的东西.而厨师就好比执行引擎. 内存是非常重要的系统资源,是硬盘和CPU的中间仓库及桥梁,承载着操作系统和应用程序的 ...
- Netty 进阶
1. 粘包与半包 1.1 粘包现象 服务端代码 public class HelloWorldServer { static final Logger log = LoggerFactory.getL ...
- Billu_b0x2内网渗透(多种提权方法)靶场-vulnhub
个人博客阅读体验更佳 本次来试玩一下vulnhub上的Billu_b0x2,下载地址. 下载下来后是 .ova 格式,建议使用vitualbox进行搭建,vmware可能存在兼容性问题.靶场推荐使用N ...
- 036—环境变量path
day04 课堂笔记 1.开发第一个java程序:HelloWorld 1.1.程序写完以后,一定要ctrl+s进行保存 源代码若修改,需重新进行编译 1.2.编译阶段 怎么编译?使用什么命令?这个命 ...
- 初学python-day2 字符串格式化1
- ZK(ZooKeeper)分布式锁实现
点赞再看,养成习惯,微信搜索[牧小农]关注我获取更多资讯,风里雨里,小农等你. 本文中案例都会在上传到git上,请放心浏览 git地址:https://github.com/muxiaonong/Zo ...