Tautology(structure)

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

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

Waterloo Local Contest, 2006.9.30

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<iostream>
 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         else
45             puts ("tautology") ;
46     }
47     return 0 ;
48 }

漂亮的使用了回溯。
转载:http://blog.csdn.net/allenlsy/article/details/4885948

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

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

时间: 2024-07-31 23:58:12

Tautology(structure)的相关文章

[ACM] POJ 3295 Tautology (构造)

Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9302   Accepted: 3549 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,

WBS(work Breakdown Structure)

WBS(work Breakdown Structure) 我们的软件是"速达"定送餐服务APP 以下是我们的WBS分析

Flask备注4(Structure)

Flask备注4(Structure) package 通过Flask可以非常简单的通过一个module(一个py文件)创建一个简单的application.这种简单程序的文件结构如下: /yourapplication /yourapplication.py /static /style.css /templates layout.html index.html login.html ... 这种结构对于较大或者复杂的程序并不合适.对于复杂程序可以通过python自带的package结构来组织

HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)

题目大概说给一张无向点带有权无向图.定义连通图的权值为图中各点权的乘积,图的权值为其包含的各连通图的权和.设$z_i$为删除i点后图的权值,求$S = (\sum\limits_{i=1}^{n}i\cdot z_i) \text{ mod } (10^9 + 7)$. 官方题解这么说的: 显然, 只要删掉关键点才会使图不联通. 对于其他点, 权值很容易计算. 首先求出所有的点双联通分量, 对于每一个点双联通分量$S$, 新建一个节点$s$, 向$S$中每个节点$v$连边. 这样一来, 新增的点

VB.NET 结构(Structure)和类(Class)的区别

类是我们用来构造 VB.NET 应用程序时的最基本的编程结构了. 那结构与类有什么相似之处与不同之处呢? 结构和类, 相同之处是都含有成员,包括构造函数.方法.属性.字段.常量.枚举和事件,都可以实现接口,都有共享的构造函数,都能对成员进行封装. 没错都有构造函数,那结构的构造函数是什么,结构难道也可被实例化成对象? 看这一段代码: Module Module1 Private Structure test Dim Name As String Dim Age As Integer Public

前端面试常见HTML问题(一)

1.什么是html       HTML(Hyper Text Mark-up Language )即超文本标记语言,是 WWW 的描述语言,由 Tim Berners-lee提出.设计 HTML 语言的目的是为了能把存放在一台电脑中的文本或图形与另一台电脑中的文本或图形方便地联系在一起,形成有机的整体,人们不用考虑具体信息是在当前电脑上还是在网络的其它电脑上.这样,你只要使用鼠标在某一文档中点取一个图标,Internet就会马上转到与此图标相关的内容上去,而这些信息可能存放在网络的另一台电脑中

ansible 学习笔记(上)

运维工具 当前常见的运维工具(Configuration)有以下一种puppret(ruby)saltstack(python)chefcfengine.... Command and Control; fabricfunc 程序发布: 手动发布 脚本发布 发布程序(运维程序) 程序发布要求:1.不能影响用户体验:2.系统不能停机:3.不能导致系统故障或造成系统完全不可用: 灰度发布模型(考虑以下两种维度):1.主机:2.用户: 发布思路: /webapps/tuangou /webapps/t

otool介绍(转http://www.mc2lab.com/?p=68)

1. Otool简介 Otool可以提取并显示ios下目标文件的相关信息,包括头部,加载命令,各个段,共享库,动态库等等.它拥有大量的命令选项,是一个功能强大的分析工具,当然还可以做反汇编的工具使用. 2. Mach-o基本结构 Mach-o包含三个基本区域: 头部(header structure). 加载命令(load command). 段(segment).可以拥有多个段(segment),每个段可以拥有零个或多个区域(section).每一个段(segment)都拥有一段虚拟地址映射到

期权激励的核心价值是:激励能人,一起和公司共同成长,实现利益共享,有钱大家一起赚(转)

编者按:本文为投稿,作者米律创始人郑明龙,文章首发于洪泰基金微信号(ID:AngelPlus001). 我服务过很多创业企业,对于期权这个概念,常常见到下面这五种误区: 第一种误区就是把期权当做奖励 奖励是什么意思呢?奖励是根据你过往的成绩,比如年会的时候用奖金奖励员工,无论是奖金还是奖品. 但期权是一种激励,着眼的是未来,很多时候有些创业企业把期权当成一种奖励,比如公司融到了下一轮,CEO 说大家辛苦了我给大家一些期权作为奖励,这是一种错误的方式.对于期权的认识,最大的误区就是分不清奖励和激励