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. Jenkins问题汇总

    1.在jenkins里使用shell,如果shell起子进程会被jenkins强制杀掉的解决方法. http://scmbob.org/start-process-in-jenkins.html

  2. powerdesigner 绘制表关系和导出sql

    1.生成图(A图,B图) 2.创建关系(palette工具栏里有个线条,主表子表关系连接即可,拖动是由顺序的,一对多即从A表往B表连接) 3.这里小说一下   一开始是CDM模式,可以在软件最顶层看到 ...

  3. 开源分布式实时计算引擎 Iveely Computing 之 安装部署(2)

          在Github中下载代码和二进制程序中,您都会看到一个bin\iveely computing目录,里面即是Iveely Computing的运行库.              以前总是有 ...

  4. javascript基础(1)

    1.前言 ECMAscript解释,用来解释JS代码 DOM 文档对象模型,浏览器在做显示时需要渲染DOM树 BOM  浏览器对象模型,可以控制浏览器的行为,代码的兼容性很差 2.基本类型 数字类型: ...

  5. [AaronYang]C#人爱学不学[6]

    不要回头,不要将就,做到这两点,人生就会简单很多幸福很多 --Aaronyang的博客(www.ayjs.net)-www.8mi.me 1. 运算符,还有哪些你能学到? 1.1 不安全运算符: si ...

  6. WCF入门(7)

    前言 前段时间忙着驾照科目二的考试,都没有机会碰自己的电脑.说起来也是第一次参加这么没信心的考试,不过好在过了. 再打个广告吧,昨天终于把下载的WCF视频全部传到了QQ群共享里面,群号37819043 ...

  7. htpasswd 详解

    Apache htpasswd命令用法详解 htpasswd建立和更新存储用户名.密码的文本文件, 用于对HTTP用户的basic认证. # /usr/local/apache/bin/htpassw ...

  8. Linux安装卸载JDK(1.7 rpm)

    一.卸载系统已有的JDK 1.查看已安装的jdk rpm -qa|grep jdk   2.卸载jdk rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66. ...

  9. FooTable高级的响应式表格jQuery插件

    FooTable是一个高级jQuery插件,允许开发者在触屏智能手机及平板电脑等小型设备上制作数据非常惊人的HTML表格.它可以将HTML表转换成可扩展的响应式表格,且通过单击某一行即可将该行数据隐藏 ...

  10. 【SGU 104】Little shop of flowers

    题意 每个花按序号顺序放到窗口,不同窗口可有不同观赏值,所有花都要放上去,求最大观赏值和花的位置. 分析 dp,dp[i][j]表示前i朵花最后一朵在j位置的最大总观赏值. dp[i][j]=max( ...