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 ...
随机推荐
- UVA 103 Stacking Boxes n维最长上升子序列
题目链接:UVA - 103 题意:现有k个箱子,每个箱子可以用n维向量表示.如果一个箱子的n维向量均比另一个箱子的n维向量大,那么它们可以套接在一起,每个箱子的n维向量可以互相交换值,如箱子(2,6 ...
- 解魔方的机器人攻略13 – 安装Lejos(上)
由 动力老男孩 发表于 2009/12/27 16:58:23 Firmware(固件)相当于是机器人的操作系统,乐高NXT出厂时已经内置了一套Firmware,并且配备了非常强大的LabVIEW开发 ...
- canvas实现"雷达扫描"效果
今天来讲解“雷达扫描”效果demo,来源于QQ群里边有群友说想要个雷达效果,就尝试写了一下. 效果图: demo链接: https://win7killer.github.io/can_demo/de ...
- FIREDAC驱动MYSQL数据库
FIREDAC驱动MYSQL数据库 FIREDAC连接MYSQL数据库需要用到LIBMYSQL.DLL这个动态库. 这个LIBMYSQL.DLL分为32位和64位两个不同的版本,对应32位或64位的M ...
- python scrapy简单爬虫记录(实现简单爬取知乎)
之前写了个scrapy的学习记录,只是简单的介绍了下scrapy的一些内容,并没有实际的例子,现在开始记录例子 使用的环境是python2.7, scrapy1.2.0 首先创建项目 在要建立项目的目 ...
- 智能选择器和语义化的CSS
本文由白牙根据Heydon Pickering的<Semantic CSS With Intelligent Selectors>所译,整个译文带有我自己的理解与思想,如果译得不好或不对之 ...
- Hive日期格式转换用法
如果想把 20180123 转换成 2018-01-23,可以使用: select from_unixtime(unix_timestamp('${p_date}','yyyymmdd'),'yyyy ...
- Spark 2.0 DataFrame map操作中Unable to find encoder for type stored in a Dataset.问题的分析与解决
转载:http://blog.csdn.net/sparkexpert/article/details/52871000 随着新版本的spark已经逐渐稳定,最近拟将原有框架升级到spark 2.0. ...
- etcd的原理分析
k8s集群使用etcd作为它的数据后端,etcd是一种无状态的分布式数据存储集群. 数据以key-value的形式存储在其中. 今天同事针对etcd集群的运作原理做了一个讲座,总结一下. A. etc ...
- CentOS7环境下SSH端口修改笔记
CentOS7环境下SSH端口修改笔记 说明: CentOS7服务器环境,默认SSH端口为22,考虑到安全方面问题,欲修改端口为62231(机器内网IP为192.168.1.31) ssh配置文件和i ...