Files
python/GESP/Level6/20241201.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

37 lines
956 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
LL s;
string str;
bool out;
int main() {
cin >> n >> s >> str;
for (int i = 0; i < n; i++) {
if (str[i] == 'U') { // 第一种操作
if (s == 1) // 根,不动
continue;
if (out) { // 超过1e12向上一层
out = false;
continue;
}
s /= 2; // 变成父节点
} else if (str[i] == 'L') { // 第二种操作
if (s * 2 > 1e12) { // 左子结点编号超过1e12向下一层
out = true;
continue;
}
s *= 2; // 变成左子结点
} else if (str[i] == 'R') { // 第三种操作
if (s * 2 + 1 > 1e12) { // 右子节点编号如果超过1E12向下一层
out = true;
continue;
}
s = s * 2 + 1; // 变成右子节点
}
}
cout << s << endl;
return 0;
}