Codeforces 960D - Full Binary Tree Queries
960D - Full Binary Tree Queries
思路:
用move1[i]记录第i层第1种操作移动的个数(对这一层的个数取模)
用move2[i]记录第i层第2种操作移动的个数(对这一层的个数取模)
查询方法:
记当前值为 x,当前层为 i,则经过操作后,他到了 x + move1[i] + move2[i] 的位置,记 x = x + move1[i] + move2[i]
则这个位置上一层的位置是 x >> 1,记 x = x >> 1
那我们只要知道 x 这个位置的值是多好就好了,因为第二种操作对值并没有影响,所以 x 这个位置的值是 x - move1[i-1],记 x = x - move1[i-1]
这样循环操作就能输出路径了
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a)) LL move1[], move2[];
int main() {
int q, t;
LL x, k;
scanf("%d", &q);
while (q--) {
scanf("%d", &t);
if (t == ) {
scanf("%lld%lld", &x, &k);
int dep = ;
while (x) {
x >>= ;
dep++;
}
LL mod = 1LL << (dep - );
move1[dep] = ((move1[dep] + k ) % mod + mod) % mod;
}
else if (t == ) {
scanf("%lld%lld", &x, &k);
int dep = ;
while (x) {
x >>= ;
dep++;
}
LL mod = 1LL << (dep - );
move2[dep] = ((move2[dep] + k) % mod + mod) % mod;
}
else {
scanf("%lld", &x);
LL tx = x;
int dep = ;
while (tx) {
dep++;
tx >>= ;
}
bool f = true;
while (x) {
printf("%lld ", x);
LL mod = (1LL << dep - );
LL mv = (move1[dep] + move2[dep]) % mod;
LL L = 1LL << (dep - ), R = (L << ) - ;
if(x + mv > R) x = x + mv - mod;
else x = x + mv;
x >>= ;
dep --;
mod = (1LL << dep - );
L = 1LL << (dep - ), R = (L << ) - ;
if(x - move1[dep] < L) x = x + mod - move1[dep];
else x = x - move1[dep];
}
printf("\n");
}
}
return ;
}
Codeforces 960D - Full Binary Tree Queries的更多相关文章
- Codeforces 960D Full Binary Tree Queries ( 思维 && 模拟 )
题意 : 给出一颗无限层的满二叉树,然后每个值为 X (根的 X 等于 1 ) 左孩子的值是 2*X,右孩子的值是 2*X+1 ,现在有两种操作,(1, x,k) 表示将 x 所在层的所有节点整体向右 ...
- Codeforces 250 E. The Child and Binary Tree [多项式开根 生成函数]
CF Round250 E. The Child and Binary Tree 题意:n种权值集合C, 求点权值和为1...m的二叉树的个数, 形态不同的二叉树不同. 也就是说:不带标号,孩子有序 ...
- 九章算法系列(#3 Binary Tree & Divide Conquer)-课堂笔记
前言 第一天的算法都还没有缓过来,直接就进入了第二天的算法学习.前一天一直在整理Binary Search的笔记,也没有提前预习一下,好在Binary Tree算是自己最熟的地方了吧(LeetCode ...
- Full Binary Tree(二叉树找规律)
Description In computer science, a binary tree is a tree data structure in which each node has at mo ...
- Full Binary Tree(sdut 2882)
Problem Description: In computer science, a binary tree is a tree data structure in which each node ...
- 2014年山东省第五届ACM大学生程序设计竞赛F题:Full Binary Tree
题目描述 In computer science, a binary tree is a tree data structure in which each node has at most two ...
- [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法
二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode, construct binary tree from inorder and post order traversal
Sept. 13, 2015 Spent more than a few hours to work on the leetcode problem, and my favorite blogs ab ...
随机推荐
- js通过DOM改变html和css
1.改变html输出流,通过document.write() 直接向 HTML 输出流写内容 <body> <p>段落</p> <script> doc ...
- Summarization of Tech Interviews
Summarization of Tech Interviews(技术面试总结) 手心网(2015) Q1. 解释一下 TCP/IP 协议之滑动窗口? 滑动窗口协议的维基:https://en.wik ...
- eclipse在注释时候字体变成繁体字
输入法和java中的快捷键冲突了,按下ctrl+shift+F就切换回去了
- day28 网络编程
网络编程 什么是网络编程? 编写基于网络的应用程序的过程称之为网络编程 一.CS构架 C/S构架 服务器和客户端之间用网线连接 提供数据的计算机称为服务器,访问数据的计算机称为客户端 二.网络通讯的基 ...
- CAN通信工作原理个人心得
CAN总线结构示意图: 说明: 1:CAN收发器(示意图中的单元)根据两总线CAN_H和CAN_L的电位差来判断总线电平: 2:实际中CAN_H与CAN_L由双绞线组成: 3:数据传递终端的电阻器,是 ...
- CICD 基础
代码测试覆盖率 最近在负责相关插件的集成,今天第一次接触到"代码覆盖率"这个概念,那么,就做些简单的笔记吧. 好文 如何提高一个研发团队的"代码速度"? 代碼覆 ...
- Ubuntu 使用unzip解压乱码的问题
由于win使用的是GBK编码,在win下打包zip的压缩文件在ubuntu下使用unzip解压会出现乱码的问题. 解决方案: 换软件,不用unzip,使用unar 18.04是默认安装的,如果没有默认 ...
- tp框架中的一些疑点知识-3
rewrite就是伪静态, 伪静态就是 rewirte, 可以把入口地址隐藏掉. 兼容模式就是 普通模式 和 pathinfo模式的 结合, 前面是普通模式 ?s= , 后面的 模块/控制器/操作和参 ...
- SpringBoot 整合携程Apollo配置管理中心
携程官网对apollo的使用讲解了很多种方式的使用,但是感觉一些细节还是没讲全,特别是eureka配置中心地址的配置 这里对springboot整合apollo说一下 >SpringBoot启动 ...
- 分布式知识点总结(来自CS-Notes)
转载地址:https://github.com/CyC2018/CS-Notes/blob/master/notes/%E5%88%86%E5%B8%83%E5%BC%8F.md 注:如Paxos等的 ...