表达式的暴力模版(可以得部分分)

Posted on 2024-07-23 19:47  jacyoier  阅读(6)  评论(0编辑  收藏  举报
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=128;
 4 string s;
 5 int cnt=0;
 6 int dfs(int l,int r){
 7     int p1=-1,p2=-1;
 8     for(int i=l;i<=r;i++){
 9         if(s[i]=='|') p1=i;
10         if(s[i]=='&') p2=i;
11     }
12     if(p1!=-1){
13         int res1=dfs(l,p1-1),res2=dfs(p1+1,r);
14         if((res1&N) != ((res1|res2)&N)) cnt++;
15         return res1|res2;
16     }
17     if(p2!=-1){
18         int res1=dfs(l,p2-1),res2=dfs(p2+1,r);
19         if((res1&N) != ((res1&res2)&N)) cnt++;
20         return res1&res2;
21     }
22     return stol(s.substr(l,r-l+1));
23 }
24 int main(){
25     cin>>s;
26     cout<<dfs(0,s.size()-1)<<" "<<cnt;
27     return 0;
28 }

 

Copyright © 2025 jacyoier
Powered by .NET 9.0 on Kubernetes