博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Tautology(structure)
阅读量:4963 次
发布时间:2019-06-12

本文共 3177 字,大约阅读时间需要 10 分钟。

Tautology
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10061   Accepted: 3826

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

 

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

Source

, 2006.9.30
1 #include
2 #include
3 #include
4 using namespace std; 5 int p , q , r , s , t ; 6 int K[2][2] = {
0 , 0 , 0 , 1} , A[2][2] = {
0 , 1 , 1 , 1} , N[2] = {
1 , 0} , C[2][2] = {
1 , 1 , 0 , 1} , E[2][2] = {
1 , 0 , 0 , 1} ; 7 string st ; 8 int now ; 9 bool flag ;10 11 int calc ()12 {13 now++ ;14 switch (st[now])15 {16 case 'K' : return K[calc()][calc()] ;17 case 'A' : return A[calc()][calc()] ;18 case 'N' : return N[calc()] ;19 case 'C' : return C[calc()][calc()] ;20 case 'E' : return E[calc()][calc()] ;21 case 'p' : return p ;22 case 'q' : return q ;23 case 'r' : return r ;24 case 's' : return s ;25 case 't' : return t ;26 }27 }28 int main ()29 {30 // freopen ("a.txt" , "r" , stdin) ;31 while (cin >> st && st != "0") {32 flag = 0 ;33 for (p = 0 ; p < 2 && !flag ; p++)34 for (q = 0 ; q < 2 && !flag ; q++)35 for (r = 0 ; r < 2 && !flag ; r++)36 for (s = 0 ; s < 2 && !flag ; s++)37 for (t = 0 ; t < 2 && !flag ; t++) {38 now = -1 ;39 if ( !calc() )40 flag = true ;41 }42 if (flag)43 puts ("not") ;44 else45 puts ("tautology") ;46 }47 return 0 ;48 }
View Code

漂亮的使用了回溯。

转载:http://blog.csdn.net/allenlsy/article/details/4885948

tautology : 中文叫套套理论 , 或 永真式 , 就是无论位运算中的variable怎么变,最后答案都为1

题目里的implies 指 蕴涵 , 当且仅当 (条件q = 1) ----> (结论s = 0) 时为假 ,其余都为真

转载于:https://www.cnblogs.com/get-an-AC-everyday/p/4299525.html

你可能感兴趣的文章
DDD:再谈:实体能否处于非法状态?
查看>>
Visual Studio 2010连接MySql
查看>>
胡乱写两句
查看>>
菜鸟小队(艾妮教务系统)对于各组意见反馈
查看>>
JavaScript高级程序设计之原型对象
查看>>
SE2.3.4各试用限制调试笔记
查看>>
python console 设立快捷键 学习源码 用到英语
查看>>
JavaWeb--MVC案例1-------(5)添加
查看>>
C# WebApi使用AttributeRoutes特性路由
查看>>
区块链基础语言(十三)——Go语言函数(上)
查看>>
linux下phpstudy环境的安装
查看>>
FileMonitorKit 文件操作监控工具
查看>>
[ExtJS5学习笔记]第十三节 Extjs5的Ext.each方法学习
查看>>
UVA 110020 Efficient Solutions (STL)
查看>>
40 Java语言基础数组的初始化之静态初始化及内存图
查看>>
IOS:UI设计之UILable相关基础
查看>>
winform中的时间轴控件
查看>>
PHP-PHP.INI常用配置详解
查看>>
Linux-系统负载
查看>>
团队Alpha冲刺(九)
查看>>