五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

P8815-CSP-J-2022-3-LogicExpression邏輯表達(dá)式

2023-08-07 11:17 作者:信奧賽USACO鄭老師  | 我要投稿

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXV=1e6;

struct node{

? ? char v;

? ? int l,r;

};

vector<node> g(MAXV);

int build_tree(string sl){

? ? int last=1;

? ? stack<int> st;

? ? for(int i=0;i<sl.size();i++){

? ? ? ? if(sl[i]=='0'||sl[i]=='1'){

? ? ? ? ? ? g[last].v=sl[i];

? ? ? ? ? ? st.push(last);

? ? ? ? ? ? last++;

? ? ? ? }

? ? ? ? if(sl[i]=='&'||sl[i]=='|'){

? ? ? ? ? ? int o2=st.top();

? ? ? ? ? ? st.pop();

? ? ? ? ? ? int o1=st.top();

? ? ? ? ? ? st.pop();

? ? ? ? ? ? g[last].l=o1;

? ? ? ? ? ? g[last].r=o2;

? ? ? ? ? ? g[last].v=sl[i];

? ? ? ? ? ? st.push(last);

? ? ? ? ? ? last++;

? ? ? ? }

? ? }

? ? return st.top();

}

int dfs(int root, int& a, int& b){

? ? if(g[root].l==0&&g[root].r==0){//leaf

? ? ? ? return g[root].v-'0';

? ? }

? ? int left=dfs(g[root].l,a,b);

? ? int ret=-1;

? ? if(g[root].v=='&'){

? ? ? ? if(left==0){

? ? ? ? ? ? a++;

? ? ? ? ? ? ret=0;

? ? ? ? }else{

? ? ? ? ? ? ret=dfs(g[root].r,a,b);

? ? ? ? }

? ? }else{

? ? ? ? if(g[root].v=='|'){

? ? ? ? ? ? if(left==1){

? ? ? ? ? ? ? ? b++;

? ? ? ? ? ? ? ? ret=1;

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ret=dfs(g[root].r,a,b);

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? return ret;

}

string m2l(string s){

? ? string res;

? ? stack<char> st;

? ? for(int i=0;i<s.size();i++){

? ? ? ? char c=s[i];

? ? ? ? switch(c){

? ? ? ? ? ? case '0':

? ? ? ? ? ? case '1':

? ? ? ? ? ? ? ? res+=c;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case '(':

? ? ? ? ? ? ? ? st.push(c);

? ? ? ? ? ? ? ? break;? ??

? ? ? ? ? ? case ')':

? ? ? ? ? ? ? ? while(st.top()!='('){

? ? ? ? ? ? ? ? ? ? res+=st.top();

? ? ? ? ? ? ? ? ? ? st.pop();

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? st.pop();

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case '&':

? ? ? ? ? ? ? ? while(st.size()>0&&st.top()!='|'&&st.top()!='('){

? ? ? ? ? ? ? ? ? ? res+=st.top();

? ? ? ? ? ? ? ? ? ? st.pop();

? ? ? ? ? ? ? ? }? ??

? ? ? ? ? ? ? ? st.push('&');

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case '|':

? ? ? ? ? ? ? ? while(st.size()>0&&st.top()!='('){

? ? ? ? ? ? ? ? ? ? res+=st.top();

? ? ? ? ? ? ? ? ? ? st.pop();

? ? ? ? ? ? ? ? }? ??

? ? ? ? ? ? ? ? st.push('|');

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? default:

? ? ? ? ? ? ? ? cout<<"error1\n";

? ? ? ? }

? ? }

? ? while(st.size()>0){

? ? ? ? res+=st.top();

? ? ? ? st.pop();

? ? }

? ? return res;? ? ? ? ? ? ? ? ? ??

}

int main(){

? ? string s,sl;

? ? cin>>s;

? ? sl=m2l(s);

? ? int root=build_tree(sl);

? ? int a=0,b=0;

? ? cout<<dfs(root,a,b)<<endl;

? ? cout<<a<<" "<<b<<endl;

? ? return 0;

}


P8815-CSP-J-2022-3-LogicExpression邏輯表達(dá)式的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
苍山县| 南木林县| 固镇县| 通化市| 石家庄市| 榆林市| 澄城县| 奈曼旗| 阳江市| 长汀县| 淮南市| 安康市| 铜鼓县| 松潘县| 巴彦县| 固安县| 镇远县| 五河县| 永平县| 松原市| 射洪县| 容城县| 五常市| 布尔津县| 济宁市| 彩票| 郯城县| 沈丘县| 嘉善县| 同仁县| 石泉县| 垫江县| 惠州市| 玉屏| 南京市| 迭部县| 车险| 元阳县| 方城县| 聊城市| 固镇县|