• Codeforces1078E


    我们可以支持如果当前格子是 空/0/1 向某个方向走一步

    • 如果当前格子是 1 向右走一步: rlst
    • 如果当前格子是空向左走一步: rltl

    可以支持将当前位置的 0/1 复制到自己的某个方向,也可以支持复制后异或 1

    • 将当前位置复制到上面一个格子: u10dt
    • 将当前位置异或 1 的值复制到上面一个格子: u01dt

    还可以支持位运算操作

    • 将当前位置变成和右边一个位置的 and:0rt
    • 将当前位置变成和右边一个位置的 or:rr01ltl10rtl1rt

    异或操作比较麻烦,我们可以支持这样一个操作

    • 如果当前位置是 0,且右边的格子位置也是 0,将右边的右边的格子设成 0/1:rltrlt(0/1)

    但是这样无法确定最后所在的位置,我们可以在左边的几个格子处放一个 0,做完上面的操作后执行:lllrltl

    还有一种不用讨论的异或方法,对于两个布尔变量 a 和 b,我们有 a ^ b = (!a & b) | (a & !b),用前面的两种位运算操作就行了

    然后就是大讨论了

    spj

    #include <bits/stdc++.h>
    #define rep(i, a, b) for (int i = a; i <= b; i++)
    #define per(i, a, b) for (int i = a; i >= b; i--)
    using namespace std;
    
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef long long ll;
    
    template <typename _T>
    inline void read(_T &f) {
    	f = 0; _T fu = 1; char c = getchar();
    	while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    	while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    	f *= fu;
    }
    
    template <typename T>
    void print(T x) {
    	if (x < 0) putchar('-'), x = -x;
    	if (x < 10) putchar(x + 48);
    	else print(x / 10), putchar(x % 10 + 48);
    }
    
    template <typename T>
    void print(T x, char t) {
    	print(x); putchar(t);
    }
    
    const int N = 1e5 + 5;
    
    map <pii, bool> a[N];
    int x[N], y[N];
    int now = 0;
    
    void doit(char c) {
    	if (c == '0') {
    		++now;
    		a[now] = a[now - 1]; x[now] = x[now - 1]; y[now] = y[now - 1];
    		a[now][make_pair(x[now], y[now])] = 0;
    	}
    	if (c == '1') {
    		++now;
    		a[now] = a[now - 1]; x[now] = x[now - 1]; y[now] = y[now - 1];
    		a[now][make_pair(x[now], y[now])] = 1;
    	}
    	if (c == 'e') {
    		++now;
    		a[now] = a[now - 1]; x[now] = x[now - 1]; y[now] = y[now - 1];
    		a[now].erase(make_pair(x[now], y[now]));
    	}
    	if (c == 'l') {
    		++now;
    		a[now] = a[now - 1]; x[now] = x[now - 1]; y[now] = y[now - 1];
    		--x[now];
    	}
    	if (c == 'r') {
    		++now;
    		a[now] = a[now - 1]; x[now] = x[now - 1]; y[now] = y[now - 1];
    		++x[now];
    	}
    	if (c == 'u') {
    		++now;
    		a[now] = a[now - 1]; x[now] = x[now - 1]; y[now] = y[now - 1];
    		++y[now];
    	}
    	if (c == 'd') {
    		++now;
    		a[now] = a[now - 1]; x[now] = x[now - 1]; y[now] = y[now - 1];
    		--y[now];
    	}
    	if (c == 's') {
    		++now;
    		a[now] = a[now - 1]; x[now] = x[now - 1]; y[now] = y[now - 1];
    	}
    	if (c == 't') {
    		int cnt = 0;
    		if (a[now].count(make_pair(x[now], y[now]))) cnt = a[now][make_pair(x[now], y[now])] + 1;
    		now = max(0, now - cnt);
    	}
    }
    
    void print() {
    	for (int j = 5; j >= -5; j--) {
    		for (int i = -40; i <= 5; i++) {
    			if (a[now].count(make_pair(i, j))) {
    				if (i == x[now] && j == y[now]) {
    					if (a[now][make_pair(i, j)] == 0) putchar('P');
    					else putchar('Q');
    				} else putchar(a[now][make_pair(i, j)] + '0');
    			} else if (i == x[now] && j == y[now]) {
    				putchar('#');
    			} else {
    				putchar('.');
    			}
    		}
    		putchar('
    ');
    	}
    }
    
    int main() {
    	int n, m;
    	read(n); read(m);
    	int nowpos = 0;
    	while (n) {
    		a[0][make_pair(nowpos, 1)] = n % 2;
    		n /= 2; --nowpos;
    	}
    	nowpos = 0;
    	while (m) {
    		a[0][make_pair(nowpos, 0)] = m % 2;
    		m /= 2; --nowpos;
    	}
    	print();
    	while (1) {
    		char c = getchar();
    		while (!isdigit(c) && !isalpha(c)) c = getchar();
    		doit(c);
    		print();
    	}
    	return 0;
    }
    
  • 相关阅读:
    Linux C多线程实现生产者消费者
    数据库视图创建学习
    jsp生成好看的验证码
    每日英语
    ES6学习笔记(一)——let和const
    dataTables的导出Excel功能
    jquery生成二维码图片
    angular2表单初体验
    echarts系列之动态加载数据
    js刷新页面方法
  • 原文地址:https://www.cnblogs.com/LJC00118/p/13649576.html
Copyright © 2020-2023  润新知