Tautology
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7716   Accepted: 2935

Description

WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some subset of the possible symbols K, A, N, C, E, p, q, r, s, t. A Well-formed formula (WFF) is any string of these symbols obeying the following rules:

  • p, q, r, s, and t are WFFs
  • if w is a WFF, Nw is a WFF
  • if w and x are WFFs, Kwx, Awx, Cwx, and Ewx are WFFs.

The meaning of a WFF is defined as follows:

  • p, q, r, s, and t are logical variables that may take on the value 0 (false) or 1 (true).
  • K, A, N, C, E mean and, or, not, implies, and equals as defined in the truth table below.
Definitions of K, A, N, C, and E
     w  x   Kwx   Awx    Nw   Cwx   Ewx
  1  1   1   1    0   1   1
  1  0   0   1    0   0   0
  0  1   0   1    1   1   0
  0  0   0   0    1   1   1

tautology is a WFF that has value 1 (true) regardless of the values of its variables. For example, ApNp is a tautology because it is true regardless of the value of p. On the other hand, ApNq is not, because it has the value 0 for p=0, q=1.

You must determine whether or not a WFF is a tautology.

Input

Input consists of several test cases. Each test case is a single line containing a WFF with no more than 100 symbols. A line containing 0 follows the last case.

Output

For each test case, output a line containing tautology or not as appropriate.

Sample Input

ApNp
ApNq
0

Sample Output

tautology
not

Source

题意:K  A  N  C  E 分别代表了不同的运算符,然后用栈模拟即可,,,构造法。。。。。。。。。。。。

#include<iostream>
#include<cstdio>
#include<stack>
#include<cstring> using namespace std; const int N=; char str[N];
int p,q,r,s,t;
stack<int> st; int isvariables(char ch){
switch(ch){
case 'p':st.push(p);return ;
case 'q':st.push(q);return ;
case 'r':st.push(r);return ;
case 's':st.push(s);return ;
case 't':st.push(t);return ;
}
return ;
} void operators(char op){
switch(op){
case 'K':{
int x=st.top(); st.pop();
int y=st.top(); st.pop();
st.push(x && y);
}break;
case 'A':{
int x=st.top(); st.pop();
int y=st.top(); st.pop();
st.push(x || y);
}break;
case 'N':{
int x=st.top(); st.pop();
st.push(!x);
}break;
case 'C':{
int x=st.top(); st.pop();
int y=st.top(); st.pop();
st.push((!x) || y);
}break;
case 'E':{
int x=st.top(); st.pop();
int y=st.top(); st.pop();
st.push(x==y);
}break;
}
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%s",str) && str[]!=''){
int len=strlen(str);
int flag=;
for(p=;p<= && flag;p++)
for(q=;q<= && flag;q++)
for(r=;r<= && flag;r++)
for(s=;s<= && flag;s++)
for(t=;t<= && flag;t++){
for(int i=len-;i>=;i--)
if(!isvariables(str[i]))
operators(str[i]);
int last=st.top();
st.pop();
if(last==)
flag=;
}
if(flag)
printf("tautology\n");
else
printf("not\n");
}
return ;
}

POJ 3295 Tautology (构造法)的更多相关文章

  1. POJ 3295 Tautology(构造法)

    题目网址:http://poj.org/problem?id=3295 题目: Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

  2. poj 3295 Tautology (构造)

    题目:http://poj.org/problem?id=3295 题意:p,q,r,s,t,是五个二进制数. K,A,N,C,E,是五个运算符. K:&& A:||N:! C:(!w ...

  3. POJ 3295 Tautology 构造 难度:1

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9580   Accepted: 3640 Descrip ...

  4. [ACM] POJ 3295 Tautology (构造)

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9302   Accepted: 3549 Descrip ...

  5. POJ 3295 Tautology(构造法)

    http://poj.org/problem?id=3295 题意: 判断表达式是否为永真式. 思路: 把每种情况都枚举一下. #include<iostream> #include< ...

  6. 构造 + 离散数学、重言式 - POJ 3295 Tautology

    Tautology Description WFF 'N PROOF is a logic game played with dice. Each die has six faces represen ...

  7. POJ 3295 Tautology (构造题)

    字母:K, A, N, C, E 表示逻辑运算 字母:p, q, r, s, t 表示逻辑变量 0 或 1 给一个字符串代表逻辑表达式,如果是永真式输出tautology 否则输出not 枚举每个逻辑 ...

  8. poj 3295 Tautology(栈)

    题目链接:http://poj.org/problem?id=3295 思路分析:判断逻辑表达式是否为永真式问题.根据该表达式的特点,逻辑词在逻辑变量前,类似于后缀表达式求值问题. 算法中使用两个栈, ...

  9. poj3295 Tautology —— 构造法

    题目链接:http://poj.org/problem?id=3295 题意: 输入由p.q.r.s.t.K.A.N.C.E共10个字母组成的逻辑表达式, 其中p.q.r.s.t的值为1(true)或 ...

随机推荐

  1. bzoj 1565 [NOI2009]植物大战僵尸 解题报告

    1565: [NOI2009]植物大战僵尸 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2161  Solved: 1000[Submit][Stat ...

  2. Ubuntu 常用命令大全

    Ubuntu 常用命令大全查看软件 xxx 安装内容#dpkg -L xxx查找软件#apt-cache search 正则表达式查找文件属于哪个包#dpkg -S filename apt-file ...

  3. 混沌数学之Henon吸引子

    Henon吸引子是混沌与分形的著名例子. 相关软件:混沌数学及其软件模拟相关代码: // http://wenku.baidu.com/view/d51372a60029bd64783e2cc0.ht ...

  4. SSM(SpringMVC+Spring+Mybatis)框架程序on IDEA

    有了之前文章搭建的SSH框架之后,现在搭建基于Mybatis的框架.主要基于如下这篇文章: http://blog.csdn.net/gallenzhang/article/details/51932 ...

  5. unity forward renderer的 base pass rt设置

    一般他都是用 RenderTexture::SetActive()来设置rt 但是 forward path 的opaque我跟了好久找不到这个setactive 在dorender之前有setupR ...

  6. 新鲜出炉!9个超高分辨率的iPhone 6原型素材打包下载

    iPhone 6 出场,设计师又有得忙活了,但是新鲜的资源你们在哪里?!今天我们收集了一组精致的iPhone 6 模型素材,超高分辨率,多种视图,全都打包完毕,点一下就可以拿回家!赶紧来取吧!——   ...

  7. Android -- ViewPager放入多个XML监听每个的控件

    我这这里就用了两个imageButton的监听器,两个XML上分别一个. 昨天做了个Viewpager,今天想试试在上面弄上Button试试,结果,弄不来,然后查文档,没查到...百度了1个多小时才出 ...

  8. Inner Classes with TypeScript

    原文:https://blog.oio.de/2014/03/21/inner-classes-typescript/ b.ts class Foo { sex:string; say(){ new ...

  9. 查看sedna创建的数据库和集合,文档之类

    在sedna的安装文件夹下.看一下cfg文件夹: <pre name="code" class="plain">[xuzhina@localhost ...

  10. Drupal 通过API动态的加入样式文件

    前面几篇文章中讲到关于样式的载入方式.已经了解到能够通过 theme.info 载入样式文件,但都须要更新缓存才干够使用.因些这样子没有办法动态的载入一些样式文件,在DP中提供了两个API操作样式文件 ...