Tautology - poj 3295
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10437 | Accepted: 3963 |
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
p,q,r,s,t,是五个二进制数。
K,A,N,C,E,是五个运算符。
K:&&
A:||
N:!
C:(!w)||x
E:w==x
这道题可以将p,q,r,s,t穷举
#include <iostream>
#include<string.h>
#include <stack>
using namespace std;
int p, q, r, s, t;
int len;
char str[];
int result() {
stack<int> res;
int t1,t2;
for (int i = len - ; i >= ; i--) {
switch (str[i]) {
case 'p':
res.push(p);
break;
case 'q':
res.push(q);
break;
case 'r':
res.push(r);
break;
case 's':
res.push(s);
break;
case 't':
res.push(t);
break;
case 'K':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if (t1 & t2) {
res.push();
} else {
res.push();
}
break;
case 'A':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if (t1 | t2)
res.push();
else
res.push();
break;
case 'N':
t1 = res.top();
res.pop();
if (~t1 & )
res.push();
else
res.push();
break;
case 'C':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if ((~t1 & ) | t2) {
res.push();
} else {
res.push();
}
break;
case 'E':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if (t1 == t2) {
res.push();
} else {
res.push();
}
break;
}
}
return res.top();
} int fun() {
int flag;
for (p = ; p < ; p++) {
for (q = ; q < ; q++) {
for (r = ; r < ; r++) {
for (s = ; s < ; s++) {
for (t = ; t < ; t++) {
flag = result();
if(flag==)
return ;
}
}
}
}
}
return ;
} int main() {
while (cin >> str) {
if (strcmp(str, "") == )
break;
len = strlen(str);
int flag=fun();
if(flag)
cout<<"tautology"<<endl;
else
cout<<"not"<<endl;
}
}
Tautology - poj 3295的更多相关文章
- poj 3295 Tautology (构造)
题目:http://poj.org/problem?id=3295 题意:p,q,r,s,t,是五个二进制数. K,A,N,C,E,是五个运算符. K:&& A:||N:! C:(!w ...
- poj 3295 Tautology(栈)
题目链接:http://poj.org/problem?id=3295 思路分析:判断逻辑表达式是否为永真式问题.根据该表达式的特点,逻辑词在逻辑变量前,类似于后缀表达式求值问题. 算法中使用两个栈, ...
- POJ 3295 Tautology(构造法)
http://poj.org/problem?id=3295 题意: 判断表达式是否为永真式. 思路: 把每种情况都枚举一下. #include<iostream> #include< ...
- poj 3295 Tautology 伪递归
题目链接: http://poj.org/problem?id=3295 题目描述: 给一个字符串,字符串所表示的表达式中p, q, r, s, t表示变量,取值可以为1或0.K, A, N, C, ...
- POJ 3295 Tautology(构造法)
题目网址:http://poj.org/problem?id=3295 题目: Tautology Time Limit: 1000MS Memory Limit: 65536K Total Su ...
- 构造 + 离散数学、重言式 - POJ 3295 Tautology
Tautology Description WFF 'N PROOF is a logic game played with dice. Each die has six faces represen ...
- POJ 3295 Tautology (构造题)
字母:K, A, N, C, E 表示逻辑运算 字母:p, q, r, s, t 表示逻辑变量 0 或 1 给一个字符串代表逻辑表达式,如果是永真式输出tautology 否则输出not 枚举每个逻辑 ...
- poj 3295 Tautology
点击打开链接 Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8127 Accepted: 3115 ...
- POJ 3295 Tautology 构造 难度:1
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9580 Accepted: 3640 Descrip ...
随机推荐
- dubbo的中文官网
https://dubbo.gitbooks.io/dubbo-user-book/content/preface/background.html
- InputSplit—>RecordReder—>map(key,value,context)的过程解析
上图首先描述了在TaskTracker端Task(MapTask.ReduceTask)的执行过程,MapTask(org.apache.hadoop.mapred)首先被TaskRunner调用,然 ...
- Android 更新UI的两种方法——handler和runOnUiThread()
今天看到了一个runOnUiThread()方法用来更新UI,觉得很神奇!! 方法一:handler机制不说了. 方法二:利用Activity.runOnUiThread(Runnable)把更新ui ...
- 使用ubifs格式的根文件系统---过程记录
配置内核,使其支持ubifs文件系统 1)Device Drivers --->Memory Technology Device (MTD) support --->UBI - Uns ...
- ios unit test 工程选择release时候报错Undefined symbols for architecture i386
Undefined symbols for architecture i386: "_OBJC_CLASS_$_ItemReturn", referenced from: objc ...
- [置顶]
kubernetes资源类型--持久化存储Persistent Volume和Persistent Volume Claim
概念 存储管理跟计算管理是两个不同的问题.理解每个存储系统是一件复杂的事情,特别是对于普通用户来说,有时并不需要关心各种存储实现,只希望能够安全可靠地存储数据. 为了简化对存储调度,K8S对存储的供应 ...
- iptables利用connlimit模块限制同一IP连接数
connlimit功能: connlimit模块允许你限制每个客户端IP的并发连接数,即每个IP同时连接到一个服务器个数. connlimit模块主要可以限制内网用户的网络使用,对服务器而言则可以限制 ...
- 【Zookeeper】Zookeeper部署笔记
Zookeeper部署笔记 .上传zk安装包 .解压 .配置(先在一台节点上配置) .1添加一个zoo.cfg配置文件 $ZOOKEEPER/conf mv zoo_sample.cfg zoo.cf ...
- ssh免密码登录的注意事项
centos配置完免密码登录(注意修改配置文件,/etc/ssh/sshd_config),合并完公钥后,有的时候还得需要输入密码.这时候应该检查一下authorized_keys的权限问题.本机的正 ...
- 右键添加"在此处打开命令窗口"菜单
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\Background\shell\CMD] @="在此 ...