POJ 3295 Tautology(构造法)
http://poj.org/problem?id=3295
题意:
判断表达式是否为永真式。
思路:
把每种情况都枚举一下。
#include<iostream>
#include<string>
#include<cstring>
using namespace std; const int MAXN = ; int sta[MAXN];
char str[MAXN];
int p, q, r, s, t; void judge()
{
int top = ;
int len = strlen(str);
for (int i = len - ; i >= ; i--)
{
if (str[i] == 'p') sta[top++] = p;
else if (str[i] == 'q') sta[top++] = q;
else if (str[i] == 'r') sta[top++] = r;
else if (str[i] == 's') sta[top++] = s;
else if (str[i] == 't') sta[top++] = t;
else if (str[i] == 'K')
{
int t1 = sta[--top];
int t2 = sta[--top];
sta[top++] = (t1&&t2);
}
else if (str[i] == 'A')
{
int t1 = sta[--top];
int t2 = sta[--top];
sta[top++] = (t1 || t2);
}
else if (str[i] == 'N')
{
int t1 = sta[--top];
sta[top++] = (!t1);
}
else if (str[i] == 'C')
{
int t1 = sta[--top];
int t2 = sta[--top];
if (t1 == && t2 == )sta[top++] = ;
else sta[top++] = ;
}
else if (str[i] == 'E')
{
int t1 = sta[--top];
int t2 = sta[--top];
if ((t1 == && t2 == ) || (t1 == && t2 == )) sta[top++] = ;
else sta[top++] = ;
}
}
} bool solve()
{
for (p = ; p<; p++)
for (q = ; q<; q++)
for (r = ; r<; r++)
for (s = ; s<; s++)
for (t = ; t<; t++)
{
judge();
if (sta[] == )return false;
}
return true;
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
while (gets(str) && str[] != '')
{
if (solve()) cout << "tautology" << endl;
else cout << "not" << endl;
}
return ;
}
POJ 3295 Tautology(构造法)的更多相关文章
- POJ 3295 Tautology(构造法)
题目网址:http://poj.org/problem?id=3295 题目: Tautology Time Limit: 1000MS Memory Limit: 65536K Total Su ...
- 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 构造 难度:1
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9580 Accepted: 3640 Descrip ...
- [ACM] POJ 3295 Tautology (构造)
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9302 Accepted: 3549 Descrip ...
- POJ 3295 Tautology (构造法)
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7716 Accepted: 2935 Descrip ...
- 构造 + 离散数学、重言式 - 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(栈)
题目链接:http://poj.org/problem?id=3295 思路分析:判断逻辑表达式是否为永真式问题.根据该表达式的特点,逻辑词在逻辑变量前,类似于后缀表达式求值问题. 算法中使用两个栈, ...
- poj3295 Tautology —— 构造法
题目链接:http://poj.org/problem?id=3295 题意: 输入由p.q.r.s.t.K.A.N.C.E共10个字母组成的逻辑表达式, 其中p.q.r.s.t的值为1(true)或 ...
随机推荐
- 001-nginx基础配置-location
一.基础语法 Location block 的基本语法形式是: location [=|~|~*|^~|@] pattern { ... } [=|~|~*|^~|@] 被称作 location mo ...
- [vue]webpack&vue组件工程化实践
[vue]全局组件和局部组件(嵌套+props引用父组件数据) [vue]组件篇 [vue]组件的创建(componet)和销毁(keep-alive缓存)和父子dom同步nextTick [vue] ...
- ElasticSearch排序Java api简单Demo
代码: String time1 = ConstValue.GetCurrentDate(); SortBuilder sortBuilder = SortBuilders.fieldSort(&qu ...
- 连接数据库工具类DBUtil
代码如下: import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Connection; ...
- ubuntu vim python配置
参考https://www.cnblogs.com/cjy15639731813/p/5886158.html 但是后面打开文件的时候会报错,参考https://blog.csdn.net/jeff_ ...
- 神经网络前向后向传播(理论推导+代码) 单层神经网络相当于logistic regression
建立神经网络的主要步骤是: 1. 定义模型结构(例如输入特征的数量) 2. 初始化模型的参数 3. 循环: # 3.1 计算当前损失(正向传播) # 3.2 计算当前梯度(反向传播) # 3.3 更新 ...
- 33. Search in Rotated Sorted Array(二分查找)
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...
- yii2csrf攻击
第一种解决办法是关闭Csrf public function init(){ $this->enableCsrfValidation = false; } 第二种解决办法是在form表单中加入隐 ...
- 搭建Linux-java web运行环境之二:安装mysql
环境 OS:Red Hat Enterprise Linux Server release 7.3 (Maipo) JDK:jdk-7u80-linux-x64.tar.gz Tomcat:apach ...
- python excel操作单元格复制和读取的两种方法
操作单元格 新建一个sheet, 单元格赋值(两种方法) 单元格A1赋值为’xiaxiaoxu’ 单元格A2赋值为‘xufengchai’ 打印A1和A2单元格的值(两种方法) #coding=utf ...