B. Rule 110【GDUT 2022 grade Qualifying #1】

B. Rule 110

原题链接
image
image

题意

模拟转换字符串

题解

Rule 110 是一个著名的元胞自动机规则,它被认为是最简单的图灵完备系统。
这个题要我们模拟这个系统,按照题意做即可,注意开头结尾要补充 0。

代码

点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

#define X first
#define Y second

typedef pair<int,int> pii;
typedef long long LL;
const char nl = '\n';
const int N = 1e6+10;
const int M = 2e5+10;
int n,m;
int a[N];
string s,ans;

void solve(){
	cin >> n;
	cin >> s;
	if(n == 1){
		cout << s;
		return;
	}
	if(s.substr(0,2) == "00")ans+="0";
	else ans+="1";
	for(int i = 0; i <= n - 3; i ++ ){
		string t = s.substr(i,3);
		if(t == "000" || t == "111" || t == "100")ans+="0";
		else ans+="1";
	}
	if(s.substr(n-2,2) == "00" || s.substr(n-2,2) == "10")ans+="0";
	else ans+="1";
	cout << ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	solve();
}
posted @ 2023-03-05 14:57  Keith-  阅读(23)  评论(0编辑  收藏  举报