4966-Normalized Form

Source: Internet
Author: User

Http://livearchive.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 2967

First, we need to find the deepest depth, and then use parity to identify whether to perform a crossover or complement operation. An odd number indicates an operation, and an even number indicates a supplementary operation.

Note that the global variable I is used to solve the problem of repeated calculation. It is worth noting.

#include<iostream>#include<string.h>#include<stdio.h>#include<algorithm>using namespace std;char s[40000];char s2[3]="()";int i;int solve(int k,int id){    int ans=id;    for(i=++k;;i++)    {        if(s[i]==')')return ans;        else        if(s[i]=='T')        {        if(id)ans&=1;        else        ans|=1;        }        else        if(s[i]=='F')        {        if(id)ans&=0;        else        ans|=0;        }        else        if(s[i]=='(')        {        if(id)ans&=solve(i,id^1);        else        ans|=solve(i,id^1);        }    }}int main(){    int test=1;    while(cin>>s)    {        int ans=0;        int temp=0;        if(!strcmp(s,s2))break;        int len=strlen(s);        for(int j=0;j<len;j++)        {            if(s[j]=='(')temp++;            else            if(s[j]==')')                ans=max(ans,temp),temp--;        }        printf("%d. ",test++);        i=0;        temp=solve(0,ans%2);        if(temp==0)            cout<<"false"<<endl;        else            cout<<"true"<<endl;    }    //system("pause");    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.