POJ 3295 Tautology(构造法)
来源:互联网 发布:淘宝详情页价格说明 编辑:程序博客网 时间:2024/05/24 06:25
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.
- 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.
A 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
ApNpApNq0
Sample Output
tautologynot
输入由p、q、r、s、t、K、A、N、C、E共10个字母组成的逻辑表达式,
其中p、q、r、s、t的值为1或0,K、A、N、C、E为逻辑运算符
K ~ x && y A ~ x || y N ~ !x C ~ (!x)||y E ~ x==y
问这个逻辑表达式是否为永真式,否输出not
p,q,r,s,e共有32种组合方式,枚举出来判断只要有一个式子不是永真,就输出not
#include <iostream>#include <cstdio>#include <cstring>#define N 110using namespace std;char ss[N];int a[N];int top;int p,q,r,s,t;bool tf(){ int len=strlen(ss); top=0; for(int i=len-1;i>=0;i--) { if(ss[i]=='p') a[top++]=p; else if(ss[i]=='q') a[top++]=q; else if(ss[i]=='r') a[top++]=r; else if(ss[i]=='s') a[top++]=s; else if(ss[i]=='t') a[top++]=t; else if(ss[i]=='K') { int w=a[--top]; int e=a[--top]; a[top++]=(w&&e); } else if(ss[i]=='A') { int w=a[--top]; int e=a[--top]; a[top++]=(w||e); } else if(ss[i]=='N') { int w=a[--top]; a[top++]=(!w); } else if(ss[i]=='C') { int w=a[--top]; int e=a[--top]; a[top++]=(!w)||e; } else if(ss[i]=='E') { int w=a[--top]; int e=a[--top]; if(w==e) a[top++]=1; else a[top++]=0; } } if(!a[0]) return false; else return true;}bool judge(){ for(p=0; p<=1; p++) for(q=0; q<=1; q++) for(r=0; r<=1; r++) for(s=0; s<=1; s++) for(t=0; t<=1; t++) { if(!tf()) return false; } return true;}int main(){ while(~scanf("%s",ss)) { if(strcmp(ss,"0")==0) break; if(judge()) printf("tautology\n"); else printf("not\n"); } return 0;}
- POJ 3295 Tautology(构造法 stack)
- POJ 3295 Tautology (构造法 栈)
- POJ 3295 Tautology(构造法)
- poj 3295 Tautology(构造法)
- POJ 3295 Tautology(构造法)
- POJ - 3295 - Tautology (构造)
- 初级->基本算法->构造法 poj 3295 Tautology(永真式)
- POJ 3295-Tautology(构造法+栈)
- POJ 3295 Tautology(构造)(栈)
- [ACM] POJ 3295 Tautology (构造)
- POJ 3295 Tautology(递归、构造)
- POJ 3295 Tautology 构造方法
- POJ 3295 Tautology 构造 stack
- [POJ 3295]Tautology[构造][DFS]
- poj 3295 Tautology(经典构造算法题)
- Tautology(POJ3295-构造法)
- poj 3295 Tautology(枚举)
- poj3295——Tautology(构造法)
- faac源码分析之解码参数配置
- Protocol Buffer介绍(Java)
- RDIFramework.NET ━ 9.2 员工管理 ━ Web部分
- 我的学习之旅(40) sched.c
- 电采暖wifi互联网温控器手机远程控制
- POJ 3295 Tautology(构造法)
- Missing required argument 'module[s]' 缺少加载的模块信息
- ajax提交响应后台加号(+)变成空格
- Protocol Buffer技术详解(语言规范)
- 天声人語 20150131
- Rubby在青柠互动的一月份工作总结
- base64_encode() 和 base64_decode()
- redis 常用命令记录
- hdu 4283 区间dp+对出栈顺序的理解+前缀和