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, N-w is a WFF
- If w and x are wffs, Kwx, Awx, Cwx, and Ewx is wffs.
The meaning of a WFF is defined as follows:
- P, Q, R, S, and T is logical variables that could 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 |
K wx |
A WX |
N w |
C wx |
E wx |
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 have value 1 (true) regardless of the values of its variables. For example, Apnp are a tautology because it is true regardless of the value of p. On the other hand, apnq was not , because it had 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 was a single line containing a WFF with no more than symbols. A line containing 0 follows.
Output
For each test case, the output a line containing tautology or not as appropriate.
Sample Input
ApNpApNq0
Sample Output
Tautologynot
Source
Waterloo Local Contest, 2006.9.30
1#include <stdio.h>2#include <string.h>3#include <iostream>4 using namespacestd;5 intp, Q, R, S, T;6 intk[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 stringSt;8 intNow ;9 BOOLFlag;Ten One intCalc () A { -now++ ; - Switch(St[now]) the { - Case 'K':returnK[calc ()][calc ()]; - Case 'A':returnA[calc ()][calc ()]; - Case 'N':returnN[calc ()]; + Case 'C':returnC[calc ()][calc ()]; - Case 'E':returnE[calc ()][calc ()]; + Case 'P':returnp; A Case 'Q':returnQ; at Case 'R':returnR; - Case 's':returns; - Case 'T':returnT; - } - } - intMain () in { - //freopen ("A.txt", "R", stdin); to while(Cin >> St && St! ="0") { +Flag =0 ; - for(P =0; P <2&&!flag; p++) the for(q =0; Q <2&&!flag; q++) * for(R =0; R <2&&!flag; r++) $ for(s =0; s <2&&!flag; s++)Panax Notoginseng for(t =0; T <2&&!flag; t++) { -now =-1 ; the if( !Calc ()) +Flag =true ; A } the if(flag) +Puts (" not") ; - Else $Puts ("tautology") ; $ } - return 0 ; -}
View Code
Pretty use of backtracking.
Reprint: http://blog.csdn.net/allenlsy/article/details/4885948
Tautology: The Chinese is called the condom theory, or the eternal Truth, that is, no matter how the variable change in the bitwise operation, the final answer is 1
The implies in the title refers to the implication, when and only if (condition q = 1) ----> (conclusion s = 0) is false and the rest is true
Tautology (structure)