15分……
查看原帖
15分……
749184
kszmhy楼主2022/12/5 18:06
#include<bits/stdc++.h>
using namespace std;
class Node{
public:
    bool v;
    char op;
    Node *l, *r, *up;
    bool reach,ischecked;
    Node(int v_, char op_, Node *l=0, Node *r=0, Node *up=0){
        v = v_;
        op = op_;
        this->l = l;
        this->r = r;
        this->up = up;
        reach = 0;
        ischecked = 0;
    }
};
bool check(Node * t, Node * r){
    if(t->ischecked){
        return t->reach;
    }
    bool f = 0;
    if((t->up)!=0){
        if(t->up==r){
            f = 1;
        }else{
            f = check(t->up, r);
        }
    }
    t->ischecked = 1;
    t->reach = f;
    return f;
}
Node * dat[100000+5];
stack<Node *> st;
bool x[100000 + 5];
string s;
int main(){
    getline(cin, s);
    int n;
    cin >> n;
    for (int i = 1; i <= n;i++){
        cin >> x[i];
    }
    int l = s.length();
    for (int i = 0; i < l;i++){
        if(s[i]=='x'){
            int t = 0;
            i++;
            while (s[i] != ' '){
                t = t * 10 + s[i] - '0';
                i++;
            }
            dat[t]= new Node(x[t], 'x');
            st.push(dat[t]);
        }
        else{
            if(s[i]=='&'){
                Node *r = st.top();
                st.pop();
                Node *l = st.top();
                st.pop();
                bool v = r->v & l->v;
                st.push(new Node(v, '&', l, r));
                if(r->v){
                    l->up = st.top();
                }
                if(l->v){
                    r->up = st.top();
                }
            }
            if(s[i]=='|'){

            }
            if(s[i]=='!'){

            }
        }
    }
    int k;
    cin >> k;
    for (int i = 0; i < k;i++){
        int t;
        cin >> t;
        if(check(dat[t],st.top())){
            cout << !(st.top()->v) << endl;
        }else{
            cout << (st.top()->v) << endl;
        }
    }
}
2022/12/5 18:06
加载中...