Tautology(structure)
| 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
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)的更多相关文章
- FAT文件系统规范v1.03学习笔记---2.FAT区之FAT数据结构(Fat Data Structure)
1.前言 本文主要是对Microsoft Extensible Firmware Initiative FAT32 File System Specification中文翻译版的学习笔记. 每个FAT ...
- Flask备注4(Structure)
Flask备注4(Structure) package 通过Flask可以非常简单的通过一个module(一个py文件)创建一个简单的application.这种简单程序的文件结构如下: /youra ...
- HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...
- VB.NET 结构(Structure)和类(Class)的区别
类是我们用来构造 VB.NET 应用程序时的最基本的编程结构了. 那结构与类有什么相似之处与不同之处呢? 结构和类, 相同之处是都含有成员,包括构造函数.方法.属性.字段.常量.枚举和事件,都可以实现 ...
- 面试总结之数据结构(Data Structure)
常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...
- [ACM] POJ 3295 Tautology (构造)
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9302 Accepted: 3549 Descrip ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- 奥特曼小分队之四(Work Breakdown Structure)
写在前面的话:游戏介绍http://www.cnblogs.com/atmxfd/p/5415107.html 需求 我们的游戏是一款基于局域网的游戏,用户只需将服务端和客户端置于同一局域网下即可使用 ...
- 分而治之(Work Breakdown Structure, WBS)
不知道大家有没有和我一样的情况,就是想写一篇博客,不知道从何写起,如何组织语言,如何安排这篇博客的要交待的事情的前因后果:如果在写作过程中被打断,又不知道如何重新拾起键盘,从哪里写起."就如 ...
随机推荐
- error C2065: “IDD_DIALOG1” : 未声明的标识符
编译时提示error C2065: “IDD_DIALOG1” : 未声明的标识符 错误的可能原因及解决方法如下: 1.出错文件中没有包含资源文件ID声明的resource.h文件.在出错文件中加入# ...
- 如何构建JSON数据,JSON数据的格式,JSON数据的获取
假设你是用$.getJSON();方法获取JSON数据$.getJSON(url,{"Action":"getStudent"},function(data){ ...
- Asp.net MVC在View里动态捆绑压缩引用的js
前言 Asp.net MVC 4以上版本多了BundleConfig.RegisterBundles方法,可以把要捆绑的脚本或样式进行捆绑压缩,以减少客户端的请求次数从而提高了客户端的访问速度. 问题 ...
- Java 读取文件到字符串
Java的io操作比较复杂 package cn.outofmemory.util; import java.io.BufferedReader; import java.io.FileInputSt ...
- HDU 5976 Detachment 打表找规律
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5976 Detachment Time Limit: 4000/2000 MS (Java/Other ...
- [转]不再以讹传讹,GET和POST的真正区别
原文地址:http://www.nowamagic.net/librarys/veda/detail/1919 如果有人问你,GET和POST,有什么区别?你会如何回答? 我的经历 前几天有人问我这个 ...
- UVA5870 乱搞 Smooth Visualization
#include<stdio.h> #include<string.h> #define maxn 1201 ][],s[maxn]; int col; int getmax( ...
- zoj1665 dij变形
既然输入的是损坏率,那1-x就是剩余的.最后只要剩余的最大. #include<stdio.h> #include<string.h> #define Max 99999999 ...
- 关于 Maven 的插件maven-war-plugin
在进行项目发布的时候,可能会碰到这样的情况, 希望在保持项目源代码不变的前提下,希望能够针对不同的运行环境获得相应的运行包.(比如war包) 基本配置 :(包括排除 不想打进war包的jar 的配置) ...
- iOS开发icon&images Size
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix ...