题解:B4532 [信息与未来 2026] 折纸

· · 题解

B4532 [信息与未来 2026] 折纸 题解

我是苏州小学六年级的 xxs , 信息与未来 T4 爆零了 , 写下本篇题解 , 求过

这题是一个模拟,有点水 (但我比赛爆零了)

变量有点乱 , 讲一下 :

a 和 b 是纸折后的行和列 , c 是指折纸后的层数 , d 是指折了 i 次后的层数 (等同于 pow(2,i)) , x 是指折纸后的行和 ,r 是指这之后的列 , y 指状态

AC code :

# include <bits/stdc++.h>
using namespace std;
long long n,m,a,b,c = 1,d = 1,x = 1,y = 0,r = 1;
char op,ans[2] = {'U','D'};
int main () {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    a = b = m = pow(2,n);
    for (int i = 1;i <= 2 * n;i++) {
        cin >> op;
        if (op == 'D') {
            if (r <= b / 2) {
                y = 1 - y;
                c = d - c + 1;
                r = b / 2 - r + 1;
            } else {
                r -= b / 2;
                c += d;
            }
            d *= 2;
            b /= 2;
        } else if (op == 'U') {
            if (r <= b / 2) {
                c += d;
            } else {
                y = 1 - y;
                r = b - r + 1;
                c = d - c + 1;
            }
            b /= 2;
            d *= 2;
        } else if (op == 'R') {
            if (x <= a / 2) {
                y = 1 - y;
                x = a / 2 - x + 1;
                c = d - c + 1;
            } else {
                x -= a / 2;
                c += d;
            }
            a /= 2;
            d *= 2;
        } else {
            if (x >= a / 2 + 1) {
                x = a - x + 1;
                y = 1 - y;
                c = d - c + 1;
            } else {
                c += d;
            }
            a /= 2;
            d *= 2;
        }
    }
    cout << c << ' ' << ans[y];
    return 0;
}