#include<cstdio>
#include<iostream>
#define lowbit(x) x&(-x)
typedef long long ll;
using namespace std;
ll n,q,num,root;string s;
int main()
{
scanf("%I64d%I64d",&n,&q);
root=(n+)/;
for(ll q_i=;q_i<=q;q_i++)
{
cin>>num>>s;
for(int step=;step<s.size();step++)
{
ll lowbit_num=lowbit(num);//假设num这个节点是左子节点
if(s[step]=='U' && num!=root)
{
ll num_u=num+lowbit_num;//求出在假设情况下的num的父节点num_u
ll lowbit_num_u=lowbit(num_u);
if(num_u - lowbit_num_u/ == num) num=num_u;//如果根据父节点求出来的左孩子就是num,那么num确实是左子节点
else num=num-lowbit_num;//否则num就是右子节点
}
if(s[step]=='L') num-=lowbit_num/;
if(s[step]=='R') num+=lowbit_num/;
}
printf("%I64d\n",num);
}
}

思路来自http://blog.csdn.net/Courage_kn/article/details/69218592

用#define比定义一个lowbit函数快……不过好像很多时候不能像函数那样随便用,容易出问题……

这是分别用

long long lowbit(long long x){return x&(-x);}

#define lowbit(x) x&(-x)

情况下的耗时……

codeforces 792D - Paths in a Complete Binary Tree的更多相关文章

  1. 【codeforces 792D】Paths in a Complete Binary Tree

    [题目链接]:http://codeforces.com/contest/792/problem/D [题意] 给你一棵满二叉树; 给你初始节点; 给你若干个往上走,左走,右走操作; 让你输出一系列操 ...

  2. PAT1110:Complete Binary Tree

    1110. Complete Binary Tree (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  3. [Swift]LeetCode919. 完全二叉树插入器 | Complete Binary Tree Inserter

    A complete binary tree is a binary tree in which every level, except possibly the last, is completel ...

  4. A1110. Complete Binary Tree

    Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each in ...

  5. PAT A1110 Complete Binary Tree (25 分)——完全二叉树,字符串转数字

    Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each in ...

  6. PAT 甲级 1110 Complete Binary Tree

    https://pintia.cn/problem-sets/994805342720868352/problems/994805359372255232 Given a tree, you are ...

  7. 1110 Complete Binary Tree (25 分)

    1110 Complete Binary Tree (25 分) Given a tree, you are supposed to tell if it is a complete binary t ...

  8. [二叉树建树&完全二叉树判断] 1110. Complete Binary Tree (25)

    1110. Complete Binary Tree (25) Given a tree, you are supposed to tell if it is a complete binary tr ...

  9. PAT 1110 Complete Binary Tree[判断完全二叉树]

    1110 Complete Binary Tree(25 分) Given a tree, you are supposed to tell if it is a complete binary tr ...

随机推荐

  1. python中安装dlib和cv2

    这两个模块是很容易出问题的模块,以下的解决办法都是从网上收集而来. 安装dlib: pypi.python.org/pypi/dlib/19.6.0 下载 dlib-19.6.0-cp36-cp36m ...

  2. Struts2开发模式漏洞

    当Struts2中的devMode模式设置为true时,存在严重远程代码执行漏洞.如果WEB服务以最高权限运行时,可远程执行任意命令,包括远程控制服务器. 如果为受影响的版本,建议修改配置文件stru ...

  3. hudson.AbortException: No files found in path D:\testproject\project2\testoutput\ with configured filemask: output.xml

    错误描述: hudson.AbortException: No files found in path D:\testproject\project2\testoutput\ with configu ...

  4. iOS开发-- 如何让 UITableView 的 headerView跟随 cell一起滚动

    在我们利用 UITableView 展示我们的内容的时候,我需要在顶部放一个不同于一般的cell的 界面,这个界面比较独特. 1. 所以我就把它 作为一个section的 headerView. 也就 ...

  5. 说说UART(转)

    串口协议基础 1 串口概述 串口由收发器组成.发送器是通过TxD引脚发送串行数据,接收器是通过RxD引脚接收串行数据.发送器和接收器都利用了一个移位寄存器,这个移位寄存器可以将数据进行“并转串”和“串 ...

  6. jquery on=>keyup无法绑定未来js添加的元素

    $("[name=red_count]").on("keyup", countKeyUpBind);即使使用on的,也无法绑定未来元素, 所以直接在动态添加的时 ...

  7. Git学习之Git恢复进度

    ================================================ 继续暂存区未完成的实践 ======================================= ...

  8. css笔记 - 张鑫旭css课程笔记之 z-index 篇

    一.z-index语法.支持的属性值等 z-index: 在支持z-index的元素上, z-index规定了元素(包括子元素)的垂直z方向的层级顺序, z-index可以决定哪个元素覆盖在哪个元素上 ...

  9. echarts - 特殊需求实现代码汇总之【线图】篇

    时间过得好快,刚刚还是7月底,一转眼自己调整(浪费)了大半个月的时间.. 接下来要先总结一下自己之前的知识点,然后清掉自己的待办任务,重新轻装上阵! 继7月24的echarts-柱图配置汇总后,ech ...

  10. EGL 1.0 学习笔记

    http://hi.baidu.com/leo_xxx/item/b01b1fc29abff355ac00ef5c 基本概念 EGL是OpenGL ES与本地Window系统之间的桥梁.EGL创建渲染 ...