今天继续攒人品。。。真开心啊O(∩_∩)O~~各种身体不舒服~~

https://icpcarchive.ecs.baylor.edu/external/65/6577.pdf

题意是这样的,现在有一个向下无限延伸的二叉树。然后输入起点(通过只含LRU的字符串S,从根结点开始执行)。LRU分别表示往左儿子走,往右儿子走,往爹娘处走(根结点的爹娘是自己,估计他是石头里蹦出来的)。

然后输入一个可选步骤串T。可以选择T中的子序,从起点开始走。然后问可以走到多少个不同的结点。

比赛的时候不会做啊╮(╯▽╰)╭。赛后好像有题解不过看不懂。。。。英语渣的缘故吧,我猜。。。然后看LC他们的代码,研究下终于搞懂的样子

我们可以先考虑,只有LR的情况,初始化,ans=1,L=1,R=1 。LR分别表示往左(右)走的新结点数量。然后遍历T字符串,然后如果有L则ans+=L,R+=L;其实就是往左走为往右走开辟了往右走的新结点。。。好别扭,不知道怎么解释。。建议画图模拟。。。然后如果有R则ans+=R,L+=R。。。。这个好像是做过的某一题

好了,只有LR的情况解决了=。=

然后如果是现在要up,如果是up到从根执行S串的路途中,那如果up到的结点最后一次往下走是left,那现在up上去必然的结果就是,开辟了一个往右的新结点,反过来是right也一样=。=同时答案+1

有可以参考的人(代码)真好啊~~~好像太依赖参考了。。。

复杂度就O(n)

以上都是在晕晕的状态写的=。=所以有那啥的求评论。。。

Note: 好像忘memset也AC。。。。还是不需要memset?

P.S.边吃饭边发现,那个dir是可以不用memset的~~~看来要多吃饭~~~

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <set>
using namespace std; #define ll long long
#define inf 0x3f3f3f3f
#define eps 1e-8
#define maxn 100010
#define mod 21092013 char a[maxn],b[maxn];
char dir[maxn];
int main(){
int t,ca=;
scanf("%d",&t);
while(t--){
scanf("%s%s",a,b);
//memset(dir,0,sizeof(dir));// 可以不用memset
int dep=;
int la=strlen(a),lb=strlen(b);
for(int i=;i<la;++i){
if(a[i]=='U')dep=max(dep-,);
else dir[dep++]=a[i];
}
int ans=,l=,r=;
for(int i=;i<lb;++i){
if(b[i]=='U'){
if(--dep<){
dep=;
continue;
}
ans=(ans+)%mod;
if(dir[dep]=='L')r=(r+)%mod;
else if(dir[dep]=='R')l=(l+)%mod;
}
else if(b[i]=='L'){
ans=(ans+l)%mod;
r=(r+l)%mod;
}
else if(b[i]=='R'){
ans=(ans+r)%mod;
l=(l+r)%mod;
}
}
printf("Case %d: %d\n",++ca,ans);
}
return ;
}

UVALive 6577 Binary Tree 二叉树的LRU串的更多相关文章

  1. UVALive - 6577 Binary Tree 递推+找规律

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48421 Binary Tree Time Limit: 3000MS 问题描述 Binary Tree is ...

  2. Leetcode 110 Balanced Binary Tree 二叉树

    判断一棵树是否是平衡树,即左右子树的深度相差不超过1. 我们可以回顾下depth函数其实是Leetcode 104 Maximum Depth of Binary Tree 二叉树 /** * Def ...

  3. [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)

    [Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...

  4. [LeetCode] 111. Minimum Depth of Binary Tree 二叉树的最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  5. [LeetCode] 543. Diameter of Binary Tree 二叉树的直径

    Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...

  6. [LeetCode] Serialize and Deserialize Binary Tree 二叉树的序列化和去序列化

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  7. [LeetCode] Lowest Common Ancestor of a Binary Tree 二叉树的最小共同父节点

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  8. [LeetCode] Minimum Depth of Binary Tree 二叉树的最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  9. [LeetCode] Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

随机推荐

  1. zend stuido 12.5的插件安装和xdebug调试器的配置和和配置注意

    参考: zend stuido 12.5的插件安装 zend 12.5 安装插件是按类别进行分类了的, 而且是在欢迎 界面就可以直接安装, 安装后,要重启zend才能生效 版式设计的一个基本点就是: ...

  2. django 初级(一) 配置与周边

    一.下载安装 从 https://www.djangoproject.com/download/ 下载最新的 django 版本,写本文时最新版本为 django 1.7,官方说只需要 python6 ...

  3. Markdown 写作工具选择

    Markdown 写作工具选择 候选产品 参考了少数派网站 markdown 写作工具2015年度盘点 http://sspai.com/32483, Windows 下 Markdown 的编辑工具 ...

  4. [PHP知识点乱炖]四、全局变量——小偷从良记

    本章要讲的是PHP的全局变量. 这里讲个小故事: 很多年前,一个很聪明的小偷,想去偷一户人家的钱.可是他偷不到主人的钥匙,怎么办呢? 他想到了一个办法,去之前嚼了一块口香糖,口香糖的牌子是“大大泡泡糖 ...

  5. [原] Intellij IDEA开发Android,祝还在使用eclipse的早日脱离苦海

    注: 现在推荐使用Android Studio,以后google在Android Studio上个性差异化的东西越来越多, 所以越早使用Android Studio越好,看看更新文档,使我们开发更方便 ...

  6. VPN添加静态路由表(指定程序或资源走VPN)

    在某此情况下,我们希望为VPN客户端指定线路,比如只有公司的资源或网站才使用VPN连接,其它的网络请求依然走他们自己的默认网关. 这种情况下,我们就需要给VPN客户端添加静态路由规则并取消VPN连接的 ...

  7. java历史

    1.产生: 1990年初sun公司James Gosling等员工开发java语言的雏形,最初被命名为Oak,定位于家用电器的控制和通讯,随后因为市场的需求,公司放弃计划,后面由于Internet的发 ...

  8. 3d回顾

    手把手教你玩转 CSS3 3D 技术   要玩转css3的3d,就必须了解几个词汇,便是透视(perspective).旋转(rotate)和移动(translate).透视即是以现实的视角来看屏幕上 ...

  9. Unity手游之路<四>3d旋转-四元数,欧拉角和变幻矩阵

    http://blog.csdn.net/janeky/article/details/17272625 今天我们来谈谈关于Unity中的旋转.主要有三种方式.变换矩阵,四元数和欧拉角. 定义 变换矩 ...

  10. [BZOJ1999][codevs1167][Noip2007]Core树网的核

    [BZOJ1999][codevs1167][Noip2007]Core树网的核 试题描述 设T=(V, E, W) 是一个无圈且连通的无向图(也称为无根树),每条边带有正整数的权,我们称T为树网(t ...