pj t3
  • 板块灌水区
  • 楼主隐藏人物001
  • 当前回复3
  • 已保存回复3
  • 发布时间2020/11/8 12:02
  • 上次更新2023/11/5 08:29:42
查看原帖
pj t3
233394
隐藏人物001楼主2020/11/8 12:02

如下,开不了1000000char数组,求map

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
const int N=1000100;
int n,m,i,t,t1,len,mp[100010],z[100010],res1,a[100010],p;
char c[100010],c1;
struct Node 
{
	int z,y,res,fh;   
}jd[100010];
void tree(int x)
{
	if (jd[x].fh==-1)
	{
	 mp[jd[x].z]=1;
	 return;
    }
    if (jd[x].fh==2)
     tree(jd[x].z);
    else
     {
     	if (jd[jd[x].z].res==1&&jd[x].fh==0) tree(jd[x].y);
     	if (jd[jd[x].y].res==1&&jd[x].fh==0) tree(jd[x].z);
     	if (jd[jd[x].z].res==0&&jd[x].fh==1) tree(jd[x].y);
     	if (jd[jd[x].y].res==0&&jd[x].fh==1) tree(jd[x].z);
	 }
    return;
} 
 int main()
 {
 	freopen("expr.in","r",stdin);
 	freopen("expr.out","w",stdout);
 	c1=getchar();
     while (c1!='\n')
     {
      c[p++]=c1;
      c1=getchar();
     }
     len=strlen(c);
    scanf("%d",&n);
     for (i=1;i<=n;i++)
      scanf("%d",&a[i]);
     t=0;
     t1=0;
      for (i=0;i<=len-1;i++)
       if (c[i]=='x')
        {
        	i++;
        	jd[++t].res=a[c[i]-48];
        	jd[t].fh=-1;
        	jd[t].z=c[i]-48;
        	jd[t].y=c[i]-48;
        	z[++t1]=t;
		}
		else
	    if (c[i]=='&')
	    {
	    	jd[++t].fh=0;
	    	jd[t].z=z[t1];
	    	jd[t].y=z[--t1];
	    	jd[t].res=(jd[z[t1+1]].res)&&(jd[z[t1]].res);
	    	z[t1]=t;
		}
		else
		if (c[i]=='|')
		{
	    	jd[++t].fh=1;
	    	jd[t].z=z[t1];
	    	jd[t].y=z[--t1];
	    	jd[t].res=(jd[z[t1+1]].res)||(jd[z[t1]].res);
	    	z[t1]=t;
		}
		else
		if (c[i]=='!')
		{
			jd[++t].fh=2;
	    	jd[t].z=z[t1];
	    	jd[t].res=!(jd[z[t1]].res);
	    	z[t1]=t;
		}
		res1=jd[t].res;
		memset(mp,0,sizeof(mp)); 
		tree(t);
	  scanf("%d",&m);
	   for (i=1;i<=m;i++)
	    {
	    	scanf("%d",&p);
	    	if (mp[p]==1)
	    	 printf("%d\n",!res1);
	    	 else
	    	 printf("%d\n",res1);
		}
	  fclose(stdin);
      fclose(stdout);
      return 0;
  }
2020/11/8 12:02
加载中...