Tautology

思路很简单,对于p、q、r、s、t暴力枚举是0还是1,判断即可。判断时像写表达式求值那样用栈。为了方便可以从后往前,因为最后一个肯定不是运算。那几个奇奇怪怪的函数可以找规律然后转为位运算,简洁又快。

#include<cstdio>
#include<stack>
#include<cstring>
using namespace std;
const int MAXN=105;
char a[MAXN];
int n,p,q,r,s,t;
bool ans;
bool isc(char c) {
return c=='p'||c=='q'||c=='r'||c=='s'||c=='t';
}
void push(char c,stack<int>&st) {
if(c=='p')st.push(p);
if(c=='q')st.push(q);
if(c=='r')st.push(r);
if(c=='s')st.push(s);
if(c=='t')st.push(t);
}
int K(int a,int b) {
return a&b;
}
int A(int a,int b) {
return a|b;
}
int N(int a) {
return !a;
}
int C(int a,int b) {
return (!a)|b;
}
int E(int a,int b) {
return !(a^b);
}
void calc(char c,stack<int>&st) {
if(c=='K') {
int a,b;
b=st.top(),st.pop();
a=st.top(),st.pop();
st.push(K(a,b));
}
if(c=='A'){
int a,b;
b=st.top(),st.pop();
a=st.top(),st.pop();
st.push(A(a,b));
}
if(c=='N'){
int a;
a=st.top(),st.pop();
st.push(N(a));
}
if(c=='C'){
int a,b;
b=st.top(),st.pop();
a=st.top(),st.pop();
st.push(C(a,b));
}
if(c=='E'){
int a,b;
b=st.top(),st.pop();
a=st.top(),st.pop();
st.push(E(a,b));
}
}
int main() {
while(scanf("%s",a+1)!=EOF)
{
if(!strcmp(a+1,"0"))return 0;
n=strlen(a+1);
ans=true;
for(p=0; p<=1; ++p) {
for(q=0; q<=1; ++q) {
for(r=0; r<=1; ++r) {
for(s=0; s<=1; ++s) {
for(t=0; t<=1; ++t) {
stack<int>st;
for(int i=n; i>=1; --i) {
if(isc(a[i]))push(a[i],st);
else calc(a[i],st);
}
if(!st.top())
{
ans=false;
goto end;
}
}
}
}
}
}
end:{ans?puts("tautology"):puts("not");}
}
}

POJ3295 Tautology重言式的更多相关文章

  1. [POJ3295]Tautology

    [POJ3295]Tautology 试题描述 WFF 'N PROOF is a logic game played with dice. Each die has six faces repres ...

  2. POJ-3295 Tautology (构造)

    https://vjudge.net/problem/POJ-3295 题意 有五种运算符和五个参数,现在给你一个不超过100字符的算式,问最后结果是否恒为1? 分析 首先明确各运算符的意义,K(&a ...

  3. 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)或 ...

  4. POJ3295——Tautology

    Tautology Description WFF 'N PROOF is a logic game played with dice. Each die has six faces represen ...

  5. POJ3295 Tautology(枚举)

    题目链接. 分析: 最多有五个变量,所以枚举所有的真假值,从后向前借助于栈验证是否为永真式. #include <iostream> #include <cstring> #i ...

  6. poj3295 Tautology , 计算表达式的值

    给你一个表达式,其包括一些0,1变量和一些逻辑运算法,让你推断其是否为永真式. 计算表达式的经常使用两种方法:1.递归: 2.利用栈. code(递归实现) #include <cstdio&g ...

  7. POJ3295 Tautology(栈+枚举)

    Description WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some ...

  8. ACM学习历程——POJ3295 Tautology(搜索,二叉树)

    Description WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some ...

  9. POJ3295 Tautology 解题报告

    直接上分析: 首先 弄清各种大写字母的操作的实质 K 明显 是 and   & A 是 or      | N 是 not   ! C  由表格注意到 当 w<=x 时 值为1 E  当 ...

随机推荐

  1. IP地址规划

    IP地址(Internet Protocol Address),缩写为IP Adress,是一种在Internet上的给主机统一编址的地址格式,也称为网络协议(IP协议)地址.它为互联网上的每一个网络 ...

  2. 浅谈PHP组件、框架以及Composer

    本篇文章主要介绍了PHP组件.框架以及Composer,具有一定的学习价值,感兴趣的朋友可以了解一下. 什么是组件 组件是一组打包的代码,是一系列相关的类.接口和Trait,用于帮助我们解决PHP应用 ...

  3. php 人员权限管理(RBAC)

    一.想好这个权限是什么? 就做一个就像是vip的功能,普通用户和vip用户的功能是不一样的,先来考虑一下数据库怎么设计 肯定要有用户表.还有用户所用的角色.然后就是权限功能表:可是在这里面有关联也就 ...

  4. Kali环境使用Metasploit生成木马入侵安卓手机

    Metasploit是一款开源的安全漏洞检测工具,可以帮助安全和IT专业人士识别安全性问题,验证漏洞的缓解措施,并管理专家驱动的安全性进行评估,提供真正的安全风险情报.这些功能包括智能开发,代码审计, ...

  5. java并发AtomicReference

    java并发AtomicReference AtomicReference的作用 已经介绍过AtomicInteger,AtomicIntegerArray,AtomicReference是针对对象的 ...

  6. kafka-console-consumer接收不到flume推送过来的消息

    原因和解决方法:需要先启动kafka,再启动flume,两者启动有先后顺序.

  7. 「AT1983 BBQ Hard」

    呦,来一次久违的BBQ吧! AT题...日本的题库质量一向很高 这题是有关组合数的DP... 前置芝士 快速计算组合数,具体还是自行百度. 膜域下的除法. 具体做法 题目中的问题: \(\sum_{i ...

  8. myeclipse中svn图标状态不显示问题的解决办法

    myeclipse中svn图标状态不显示问题的解决办法 博客分类: svn SVNMyeclipse工作WindowsC  myeclipse中使用 svn 插件,原本正常,未作任何更改,突然有一天, ...

  9. NFS实战

    博客实践: (1) nfs server导出/data/application/web,在目录中提供wordpress; (2) nfs client挂载nfs server导出的文件系统至/var/ ...

  10. javac导出参考文档报错 错误: 编码GBK的不可映射字符”