Jzoj4840 小W砍大树

模拟就好,dfs模拟,记录深度计算

#include<stdio.h>
#include<string.h>
char s[32010],*S; 
int dijk(char*& s,int d){
	int ret=(~d&1),v;
	for(;*s!=')';++s){
		if(*s=='('){ v=dijk(++s,d+1); ret=(d&1?ret|v:ret&v); }
		if(*s=='T'){ v=1;ret=(d&1?ret|v:ret&v); }
		if(*s=='F'){ v=0;ret=(d&1?ret|v:ret&v); }
	}
	return ret;
}
int main(){
	freopen("form.in","r",stdin);
	freopen("form.out","w",stdout);
	for(int i=1;~scanf("%s",s);++i){
		S=s+1;
		printf("%d. %s\n",i,dijk(S,0)?"true":"false");
	}
}

posted @ 2017-10-30 16:53  扩展的灰(Extended_Ash)  阅读(116)  评论(0编辑  收藏  举报