【CodeForces】792D Paths in a Complete Binary Tree
来源:互联网 发布:淘宝联盟提现手续费 编辑:程序博客网 时间:2024/05/17 08:19
考虑一下如何方便地表示树中的一个点,模拟即可
#include<stdio.h>#include<algorithm>#include<cstring>using namespace std;typedef long long ll;ll n,k;int q,len,tp;char s[100005];pair<ll,ll> st[99];#define mp(a,b) make_pair(a,b)#define fi first#define se second#define poi(a) (a.fi+a.se>>1)int main(){ scanf("%lld%d",&n,&q); while (q--) { scanf("%lld",&k); scanf("%s",s); len=strlen(s); st[tp=1]=mp(1,n); while(poi(st[tp])!=k) { if (k<poi(st[tp])) st[tp+1]=mp(st[tp].fi,poi(st[tp])-1),tp++; if (poi(st[tp])<k) st[tp+1]=mp(poi(st[tp])+1,st[tp].se),tp++; } for (int i=0;i<len;i++) { if (s[i]=='U' && poi(st[tp])!=(1+n>>1)) tp--; if (s[i]=='L' && st[tp].fi!=st[tp].se) st[tp+1]=mp(st[tp].fi,poi(st[tp])-1),tp++; if (s[i]=='R' && st[tp].fi!=st[tp].se) st[tp+1]=mp(poi(st[tp])+1,st[tp].se),tp++; } printf("%lld\n",poi(st[tp])); } }
0 0
- 【CodeForces】792D Paths in a Complete Binary Tree
- D. Paths in a Complete Binary Tree CodeForces
- Paths in a Complete Binary Tree codeforces
- Codeforces 792D Paths in a Complete Binary Tree 规律+模拟
- Educational Codeforces Round 18 D. Paths in a Complete Binary Tree
- Educational Codeforces Round 18 -- D. Paths in a Complete Binary Tree(二叉树模拟)
- CF792D:Paths in a Complete Binary Tree(数学 & 规律)
- PAT-A 1064. Complete Binary Search Tree
- PAT-A: 1110. Complete Binary Tree
- PAT(A) - 1110. Complete Binary Tree (25)
- [Google] print the outline of a complete binary tree in anti-clockwise direction
- codeforces D. Distance in Tree
- complete binary tree
- 1110. Complete Binary Tree
- Complete Binary Tree
- 1110. Complete Binary Tree
- 1110. Complete Binary Tree
- Complete Binary Search Tree
- JavaScript中的宽松相等和严格相等
- hpuoj寻找单身狗
- Unity实例.003官方示例Survival Shooter Tutorial核心代码学习
- Android 手机识别
- HDU 5976 Detachment (逆元)
- 【CodeForces】792D Paths in a Complete Binary Tree
- php 操作 redis 常用方法代码例子
- PHP实现文章定时发布设置
- linux初级学习之系统恢复2-11
- 关于move_uploaded_file()出错的问题
- 异常
- nodejs npm install -g 全局安装和非全局安装的区别
- 啥是UGC和PGC
- 2017.05.02 有关宽字符的学习