博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3295 -- Tautology
阅读量:6685 次
发布时间:2019-06-25

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

Tautology
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9075   Accepted: 3474

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 说是构造法。。哎!参考别人的思路,学习了一下。。。 http://blog.csdn.net/lyy289065406/article/details/6642766
1 /*======================================================================  2  *           Author :   kevin  3  *         Filename :   Tautology.cpp  4  *       Creat time :   2014-05-19 20:35  5  *      Description :  6  ========================================================================*/  7 #include 
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #define clr(a,b) memset(a,b,sizeof(a)) 15 #define M 115 16 using namespace std; 17 char str[M]; 18 stack
st; 19 int p,q,r,s,t,len; 20 bool judgevalue(char c) 21 { 22 if(c == 'p') st.push(p); 23 else if(c == 'q') st.push(q); 24 else if(c == 'r') st.push(r); 25 else if(c == 's') st.push(s); 26 else if(c == 't') st.push(t); 27 else return false; 28 return true; 29 } 30 void opera(char c) 31 { 32 if(c == 'K'){ 33 int x = st.top(); 34 st.pop(); 35 int y = st.top(); 36 st.pop(); 37 st.push(x && y); 38 } 39 else if(c == 'A'){ 40 int x = st.top(); 41 st.pop(); 42 int y = st.top(); 43 st.pop(); 44 st.push(x || y); 45 } 46 else if(c == 'C'){ 47 int x = st.top(); 48 st.pop(); 49 int y = st.top(); 50 st.pop(); 51 st.push((!x)||y); 52 } 53 else if(c == 'E'){ 54 int x = st.top(); 55 st.pop(); 56 int y = st.top(); 57 st.pop(); 58 st.push(x == y); 59 } 60 else if(c == 'N'){ 61 int x = st.top(); 62 st.pop(); 63 st.push(!x); 64 } 65 return; 66 } 67 bool slove() 68 { 69 bool flag = true; 70 for(p = 0; p < 2; p++){ 71 for(q = 0; q < 2; q++){ 72 for(r = 0; r < 2; r++){ 73 for(s = 0; s < 2; s++){ 74 for(t = 0; t < 2; t++){ 75 for(int ii = len-1; ii >= 0 ; ii--){ 76 if(!judgevalue(str[ii])){ 77 opera(str[ii]); 78 } 79 } 80 int ans = st.top(); 81 st.pop(); 82 if(!ans){ 83 flag = false; 84 break; 85 } 86 } 87 if(!flag) break; 88 } 89 if(!flag) break; 90 } 91 if(!flag) break; 92 } 93 if(!flag) break; 94 } 95 if(flag) return true; 96 return false; 97 } 98 int main(int argc,char *argv[]) 99 {100 while(scanf("%s",str)!=EOF){101 getchar();102 if(str[0] == '0') break;103 len = strlen(str);104 if(slove()){105 printf("tautology\n");106 }107 else printf("not\n");108 clr(str,0);109 }110 return 0;111 }
View Code

 

 

转载于:https://www.cnblogs.com/ubuntu-kevin/p/3737759.html

你可能感兴趣的文章
CLR Via CSharp读书笔记(12):泛型
查看>>
第一天Beta冲刺
查看>>
Inherits、CodeFile、CodeBehind的区别
查看>>
<script>中的async与defer属性
查看>>
scss基础
查看>>
设计模式原则总结--读《大话设计模式》有感
查看>>
struct2
查看>>
纯CSS3实现的一些酷炫效果
查看>>
faster-rcnn(testing): ubuntu14.04+caffe+cuda7.5+cudnn5.1.3+opencv3.0+matlabR2014a环境搭建记录
查看>>
ORACLE日期格式
查看>>
TestNG
查看>>
asp.net 源码坊4-5源码发布
查看>>
R语言基础3
查看>>
深度优先之货物搬运路径
查看>>
C# 基本术语概念
查看>>
Python爬虫学习笔记之点触验证码的识别
查看>>
苹果承认137名中国员工致残
查看>>
面向对象
查看>>
[1601]3n+1数链问题 sdutOJ
查看>>
jdbcTemplate 后台接口中的分页
查看>>