Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10437   Accepted: 3963

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

p,q,r,s,t,是五个二进制数。

K,A,N,C,E,是五个运算符。

K:&&

A:||
N:!

C:(!w)||x

E:w==x

这道题可以将p,q,r,s,t穷举

 #include <iostream>
#include<string.h>
#include <stack>
using namespace std;
int p, q, r, s, t;
int len;
char str[];
int result() {
stack<int> res;
int t1,t2;
for (int i = len - ; i >= ; i--) {
switch (str[i]) {
case 'p':
res.push(p);
break;
case 'q':
res.push(q);
break;
case 'r':
res.push(r);
break;
case 's':
res.push(s);
break;
case 't':
res.push(t);
break;
case 'K':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if (t1 & t2) {
res.push();
} else {
res.push();
}
break;
case 'A':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if (t1 | t2)
res.push();
else
res.push();
break;
case 'N':
t1 = res.top();
res.pop();
if (~t1 & )
res.push();
else
res.push();
break;
case 'C':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if ((~t1 & ) | t2) {
res.push();
} else {
res.push();
}
break;
case 'E':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if (t1 == t2) {
res.push();
} else {
res.push();
}
break;
}
}
return res.top();
} int fun() {
int flag;
for (p = ; p < ; p++) {
for (q = ; q < ; q++) {
for (r = ; r < ; r++) {
for (s = ; s < ; s++) {
for (t = ; t < ; t++) {
flag = result();
if(flag==)
return ;
}
}
}
}
}
return ;
} int main() {
while (cin >> str) {
if (strcmp(str, "") == )
break;
len = strlen(str);
int flag=fun();
if(flag)
cout<<"tautology"<<endl;
else
cout<<"not"<<endl;
}
}

Tautology - poj 3295的更多相关文章

  1. poj 3295 Tautology (构造)

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

  2. poj 3295 Tautology(栈)

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

  3. POJ 3295 Tautology(构造法)

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

  4. poj 3295 Tautology 伪递归

    题目链接: http://poj.org/problem?id=3295 题目描述: 给一个字符串,字符串所表示的表达式中p, q, r, s, t表示变量,取值可以为1或0.K, A, N, C, ...

  5. POJ 3295 Tautology(构造法)

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

  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

    点击打开链接 Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8127   Accepted: 3115 ...

  9. POJ 3295 Tautology 构造 难度:1

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

随机推荐

  1. [CTSC2018]假面(概率DP)

    考场上以为CTSC的概率期望题都不可做,连暴力都没写直接爆零. 结果出来发现全场70以上,大部分AC,少于70的好像极少,感觉血亏. 设a[i][j]表示到当前为止第i个人的血量为j的概率(注意特判血 ...

  2. iOS 代理 重定向消息 forwardInvocation

    今天简单研究一下iOS的重定向消息forwardInvocation: 首先看看Invocation类: @interface NSInvocation : NSObject { @private _ ...

  3. 各种计算机编码与base64

    什么是base64,base64与Hex编码,ASCII编码,UTF-8编码都是什么关系 1 计算机开始之初,二进制 计算机所用的语言是什么呢?这个语言非常简单,只有0和1两种表示.0代表否,1代表是 ...

  4. MyBatis参数为Integer型并赋值为0时判断失误的问题解决

    mybatis.xml中有if判断条件判断参数不为空时,赋值为0的Integer参数被MyBatis判断为空,因此不执行<if test="param != null and para ...

  5. c# Http Post访问接口方式

    一.json格式数据提交返回 提交和返回数据都为json格式 参数提交方式:application/json;charset=UTF-8 统一采用UTF-8字符编码 public string Pos ...

  6. eclipse 启动报错 java was started but returned code=13

    eclipse启动不了,出现“Java was started but returned exit code=13......”对话框如下 我的解决方法是:去控制面板--程序--卸载程序和功能下面查看 ...

  7. selenium 定位元素方式大全

    starts-with 顾名思义,匹配一个属性开始位置的关键字 contains 匹配一个属性值中包含的字符串 text() 匹配的是显示文本信息,此处也可以用来做定位用 eg //input[sta ...

  8. Makefile学习之通配符和自动变量

    规则中的通配符 “*” ,“?” ,“ [...]”, " % " , " wildcard " 1.“*”  *.c表示所有后缀为.C的文件: 如果文件中用到 ...

  9. python2代码升级到python3工具

    python模块lib2to3(py2转py3自动化工具) Usage: 2to3 [options] file|dir ... Options: -h, --help show this help ...

  10. 【云计算】WAF简介、功能特性、部署方式等

    之前写了一篇<WAF防御能力评测及工具>,是站在安全运维人员选型WAF产品的角度来考虑的(优先从测试角度考虑是前职业病,毕竟当过3年游戏测试?!).本篇文章从WAF产品研发的角度来YY如何 ...