• poj3295 构造法


    http://poj.org/problem?id=3295

    离散

      1 #include<iostream>
      2 #include<string.h>
      3 #include<stack>
      4 using namespace std;
      5 int p,q,r,s,t;
      6 stack<int>st;
      7 int f(char ch)
      8 {
      9     switch(ch)
     10     {
     11         case 'p':st.push(p);return 1;
     12         case 'q':st.push(q);return 1;
     13         case 'r':st.push(r);return 1;
     14         case 's':st.push(s);return 1;
     15         case 't':st.push(t);return 1;
     16     }
     17     return 0;
     18 }
     19 void  w(char ch)
     20 {
     21     switch(ch)
     22     {
     23     case 'K':
     24         {
     25             int x=st.top();
     26             st.pop();
     27             int y=st.top();
     28             st.pop();
     29             st.push(x&&y);
     30             break;
     31         }
     32     case 'A':
     33         {
     34             int x=st.top();
     35             st.pop();
     36             int y=st.top();
     37             st.pop();
     38             st.push(x||y);
     39             break;
     40         }
     41     case 'C':
     42         {
     43             int x=st.top();
     44             st.pop();
     45             int y=st.top();
     46             st.pop();
     47             st.push((!x)||y);
     48             break;
     49         }
     50     case 'E':
     51         {
     52             int x=st.top();
     53             st.pop();
     54             int y=st.top();
     55             st.pop();
     56             st.push(x==y);
     57             break;
     58         }
     59     case 'N':
     60         {
     61             int x=st.top();
     62             st.pop();
     63             st.push(!x);
     64             break;
     65         }
     66     }
     67     return;
     68 }
     69 int main()
     70 {
     71     char str[110];
     72     int len,flag;
     73     while(cin>>str&&str[0]!='0')
     74     {
     75         len=strlen(str);
     76         flag=1;
     77         for(p=0;p<=1;p++)
     78         {
     79             for(q=0;q<=1;q++)
     80             {
     81                 for(r=0;r<=1;r++)
     82                 {
     83                     for(s=0;s<=1;s++)
     84                     {
     85                         for(t=0;t<=1;t++)
     86                         {
     87                             for(int i=len-1;i>=0;i--)
     88                             {
     89                                 if(!f(str[i]))
     90                                     w(str[i]);
     91                             }
     92                             int temp=st.top();
     93                             st.pop();
     94                             if(!temp){flag=0;break;}
     95                         }
     96                         if(flag==0)break;
     97                     }
     98                     if(flag==0)break;
     99                 }
    100                 if(flag==0)break;
    101             }
    102             if(flag==0)break;
    103         }
    104         if(flag)
    105             cout<<"tautology"<<endl;
    106         else
    107             cout<<"not"<<endl;
    108     }
    109     return 0;
    110 }
    View Code
  • 相关阅读:
    css优化篇
    select超全超详细总结篇
    meta总结
    富文本编辑
    textarea 换行处理
    07 DRF响应类:Response
    06 内部类
    05 序列化组件
    04 APIView的请求生命周期
    python中if __name__ == '__main__'是什么?
  • 原文地址:https://www.cnblogs.com/sdutmyj/p/3239257.html
Copyright © 2020-2023  润新知