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

 #include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int p , q , r , s , t ;
int K[][] = { , , , } , A[][] = { , , , } , N[] = { , } , C[][] = { , , , } , E[][] = { , , , } ;
string st ;
int now ;
bool flag ; int calc ()
{
now++ ;
switch (st[now])
{
case 'K' : return K[calc()][calc()] ;
case 'A' : return A[calc()][calc()] ;
case 'N' : return N[calc()] ;
case 'C' : return C[calc()][calc()] ;
case 'E' : return E[calc()][calc()] ;
case 'p' : return p ;
case 'q' : return q ;
case 'r' : return r ;
case 's' : return s ;
case 't' : return t ;
}
}
int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
while (cin >> st && st != "") {
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++) {
now = - ;
if ( !calc() )
flag = true ;
}
if (flag)
puts ("not") ;
else
puts ("tautology") ;
}
return ;
}

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

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

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

Tautology(structure)的更多相关文章

  1. FAT文件系统规范v1.03学习笔记---2.FAT区之FAT数据结构(Fat Data Structure)

    1.前言 本文主要是对Microsoft Extensible Firmware Initiative FAT32 File System Specification中文翻译版的学习笔记. 每个FAT ...

  2. Flask备注4(Structure)

    Flask备注4(Structure) package 通过Flask可以非常简单的通过一个module(一个py文件)创建一个简单的application.这种简单程序的文件结构如下: /youra ...

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

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...

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

    类是我们用来构造 VB.NET 应用程序时的最基本的编程结构了. 那结构与类有什么相似之处与不同之处呢? 结构和类, 相同之处是都含有成员,包括构造函数.方法.属性.字段.常量.枚举和事件,都可以实现 ...

  5. 面试总结之数据结构(Data Structure)

    常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...

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

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

  7. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  8. 奥特曼小分队之四(Work Breakdown Structure)

    写在前面的话:游戏介绍http://www.cnblogs.com/atmxfd/p/5415107.html 需求 我们的游戏是一款基于局域网的游戏,用户只需将服务端和客户端置于同一局域网下即可使用 ...

  9. 分而治之(Work Breakdown Structure, WBS)

    不知道大家有没有和我一样的情况,就是想写一篇博客,不知道从何写起,如何组织语言,如何安排这篇博客的要交待的事情的前因后果:如果在写作过程中被打断,又不知道如何重新拾起键盘,从哪里写起."就如 ...

随机推荐

  1. 4.HBase In Action 第一章-HBase简介(1.1.2 数据创新)

    As we now know, many prominent internet companies, most notably Google, Amazon, Yahoo!, and Facebook ...

  2. [C语言]一个很实用的服务端和客户端进行TCP通信的实例

    本文给出一个很实用的服务端和客户端进行TCP通信的小例子.具体实现上非常简单,只是平时编写类似程序,具体步骤经常忘记,还要总是查,暂且将其记下来,方便以后参考. (1)客户端程序,编写一个文件clie ...

  3. Go-MySQL-Driver:一个Go语言的轻量级极速的mysql驱动

    Go语言的 database/sql 包的一个 MySQL驱动. 特性 轻量级与快速 原生Go语言,没有C绑定,只有纯Go 没有不安全的操作(类型转换等) 动态处理崩溃的连接 动态连接池 支持大于16 ...

  4. Qt webkit插件相关知识

    1.在Qt中使用 WebKit 浏览器核心 使用 QtWebKit 需要在工程文件(*.pro)中加入: 1.           QT +=webkit   2.           QT += n ...

  5. 【HDU 2222】Keywords Search AC自动机模板题

    参考iwtwiioi的模板写出来的.上午gty讲的并没有听懂,只好自己慢慢对着模板理解. 在HDU上为什么相同的程序提交有时T有时A!!! 奉上sth神犇的模板(不是这道题): var ch:char ...

  6. Teradata SQL tips

    Question: Insert into table_name  (1),(2),.... Teradata 貌似不能同时插入,只能一条一条插入,报错. 后来改为: Insert into tabl ...

  7. Java编程思想学习(五) 复用类

    1.继承与组合 复用类的方法有两种:继承与组合.继承就不多说了,组合就是直接在类中new一个对象. 数组也是对象,使用数组也是组合的一种. 2.初始化基类 当创建一个导出类的对象时,该对象包含一个基类 ...

  8. 33.Android之Fragment学习

    Fragment Android是在Android 3.0 (API level 11)开始引入Fragment的. 可以把Fragment想成Activity中的模块,这个模块有自己的布局,有自己的 ...

  9. SpringMVC 配置log4j

    log4j.properties相关 http://www.cnblogs.com/ITEagle/archive/2010/04/23/1718365.html http://www.cnblogs ...

  10. Bzoj2440 完全平方数

    Time Limit: 10000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Description 小 X 自幼就很 ...