10.25T1 模拟+栈
Description
![](https://oj.bashu.com.cn/images/5183-1.png)
![](https://oj.bashu.com.cn/images/5183-2.png)
很显然栈模拟一下就可以了
code:
1 #include<iostream> 2 #include<cstdio> 3 #include<stack> 4 #include<string> 5 #include<iomanip> 6 using namespace std; 7 stack<double>q; 8 double R[100005]; 9 int main(){ 10 freopen("physic.in","r",stdin); 11 freopen("physic.out","w",stdout); 12 int n; 13 cin>>n; 14 for(int i=1;i<=n;i++)cin>>R[i]; 15 string S; 16 cin>>S; 17 for(int i=0;i<S.size();i++){ 18 if(S[i]=='('){q.push(-1);} 19 if(S[i]=='R'){q.push(R[S[i+1]-'0']);i++;} 20 if(S[i]=='|'){q.push(-2);} 21 if(S[i]=='-'){q.push(-3);} 22 if(S[i]==')'){ 23 double now=q.top(); 24 q.pop(); 25 if(q.top()==-2)now=1/now; 26 int flag=0; 27 while(q.top()!=-1){ 28 if(q.top()==-3){ 29 q.pop(); 30 now+=q.top(); 31 q.pop(); 32 } 33 if(q.top()==-2){ 34 flag=1; 35 q.pop(); 36 now+=1.0/q.top(); 37 q.pop(); 38 } 39 } 40 q.pop(); 41 if(!flag) 42 q.push(now); 43 else{ 44 q.push(1.0/now); 45 } 46 } 47 } 48 cout<<fixed<<setprecision(4)<<q.top(); 49 return 0; 50 } 51 /* 52 8 53 2.3 4.5 8.1 4.0 5.6 7.7 8.8 9.1 54 (((R1-(R2|R3)-(R4|R5))|(R1-(R2|R3)-(R4|R5)))|(R8-R7-R6)) 55 */
over