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 ...
随机推荐
- [COCI2015]ZGODAN
题目大意: 给你一个数$n(n\leq10^1000)$,定义一个数是“美丽数”当且仅当这个数各个数位上的数奇偶性不同. 求最接近$n$的“美丽数”,若有多个,则依次输出. 思路: 贪心+高精度. 首 ...
- iframe和response.sendRedirect()跳转到父页面的问题
在项目中,因为为了给页面分层次,就使用了 内嵌iframe 的分了三个框.在子页面进行操作的时候,如果session超时,就要被拦截器拦截重新回到首页进行登录,但是在sub页 面 ,进行操作的时候,如 ...
- 五. 面向对象高级特性6. Java 泛型
我们知道,使用变量之前要定义,定义一个变量时必须要指明它的数据类型,什么样的数据类型赋给什么样的值. 假如我们现在要定义一个类来表示坐标,要求坐标的数据类型可以是整数.小数和字符串,例如: x = 1 ...
- 关于MapControl和PageLayout地图同步的问题
按照ArcMap的处理方式,地图和制图是分两个页面的,他们之间通过共享同一个Map对象来实现地图同步,具体做法就是在PageLayoutControl的PageLayoutReplaced事件发生时, ...
- Android Developer -- Bluetooth篇 开发实例之四 API详解
http://www.open-open.com/lib/view/open1390879771695.html 这篇文章将会详细解析BluetoothAdapter的详细api, 包括隐藏方法, 每 ...
- [置顶]
kubernetes将外部服务映射为内部服务
在实际应用中,一般不会把mysql这种重IO.有状态的应用直接放入k8s中,而是使用专用的服务器来独立部署.而像web这种无状态应用依然会运行在k8s当中,这时web服务器要连接k8s管理之外的数据库 ...
- 设计模式之工厂模式之简单工厂(php实现)
github源码地址: git@github.com:ZQCard/design_pattern.git 1.简单工厂模式 特点:将调用者与创建者分离,调用者直接向工厂请求,减少代码的耦合.提高系统的 ...
- docker 安装nginx并挂载配置文件和www目录以及日志目录
---恢复内容开始--- 一 首先 docker pull nginx 二 docker run --name myNginx -d -p 80:80 -v e:/docker/nginx/www:/ ...
- c++类型所占的字节和表示范围
一:数值类型的大杂烩 (1)short.int 和 long 类型都表示整型值.存储空间的大小不同 一般, short 类型为半个机器字长,int 类型为一个机器字长,而 long 类型为一个或两个机 ...
- ElasticSearch 排序
1.相关性排序 ElasticSearch为了按照相关性来排序,需要将相关性表示为一个数值,在 Elasticsearch 中, 相关性得分 由一个浮点数进行表示,并在搜索结果中通过 _score 参 ...