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)或 ...
随机推荐
- MySQL DBA 管理常用命令
一:在Linux下管理MySQL数据库的时候总有一些很紧急的情况,发现数据库突然变得压力很大了,那么作为一个DBA,也许需要一些常用的手段或者说命令去分析问题出现在哪里,然后解决: 数据库突然产生压力 ...
- makefile 中wildcard
在Makefile规则中,通配符会被自动展开.但在变量的定义和函数引用时,通配符将失效.这种情况下如果需要通配符有效,就需要使用函数“wildcard”,它的用法是:$(wildcard PATTER ...
- python2.7 环境配置
1.安装python2.7.8之后,配置环境变量:在path中配置python的安装路径 在cmd框中执行python,进入到python命令执行,即为配置成功. 2.执行过程中,提示缺少xlutil ...
- RNN实现字符级语言模型 - 恐龙岛(自己写RNN前向后向版本+keras版本)
问题描述:样本为所有恐龙名字,为了构建字符级语言模型来生成新的名称,你的模型将学习不同的名称模式,并随机生成新的名字. 在这里你将学习到: 如何存储文本数据以便使用rnn进行处理. 如何合成数据,通过 ...
- MySQL--教程
登入登出 首先启动服务,然后 mysql -u root -p 命令输入密码登入. mysql退出三种方法:mysql > exit;mysql > quit;mysql > \q;
- Filter—过滤器
过滤器的作用是什么? 1.拦截传入的请求和传出的响应,能拿到请求和响应中的数据 2.监视,修改,或处理正在客户端和服务器之间交换的数据流 3.利用过滤器的执行时机,实现Web程序的预处理,和后期的处 ...
- kali linux安装及配置
kali linux用户名:root 密码:之前设置过的密码 --------------------------------------------------------------------- ...
- LibSVM源码剖析(java版)
之前学习了SVM的原理(见http://www.cnblogs.com/bentuwuying/p/6444249.html),以及SMO算法的理论基础(见http://www.cnblogs.com ...
- MySQL从删库到跑路_高级(一)——数据完整性
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.数据完整性简介 1.数据完整性简介 数据冗余是指数据库中存在一些重复的数据,数据完整性是指数据库中的数据能够正确 ...
- Ubuntu系统下使用Jenkins进行项目的自动构建还是项目回滚方法
上面虽然实现了项目的自动部署,但是有时部署失败的时候我们需要回滚到指定版本的构建,这样才能更灵活的进行项目的构建部署.我们可以选择“参数化的构建过程”进行传递不同的参数来选择是进行新的构建还是回滚 如 ...